public member function
std::string::max_size
<string>
size_t max_size ( ) const;
Return maximum size of string
Returns the maximum number of characters that the
string object can hold.
Parameters
none
Return Value
The maximum number of characters a
string object can have as its content.
size_t is an unsigned integral type.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
// comparing size, length, capacity and max_size
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string str ("Test string");
cout << "size: " << str.size() << "\n";
cout << "length: " << str.length() << "\n";
cout << "capacity: " << str.capacity() << "\n";
cout << "max_size: " << str.max_size() << "\n";
return 0;
}
|
A possible output for this program could be:
size: 11
length: 11
capacity: 15
max_size: 4294967291
|
Basic template member declaration
( basic_string<charT,traits,Allocator> )
1 2
|
typedef typename Allocator::size_type size_type;
size_type max_size() const;
|
See also
- string::capacity
- Return size of allocated storage (public member function)
- string::size
- Return length of string (public member function)
- string::resize
- Resize string (public member function)