public member function
size_t max_size() const noexcept;
Return maximum size of string
Returns the maximum length the string can reach.
This is the maximum potential length the string can reach due to known system or library implementation limitations, but the object is not guaranteed to be able to reach that length: it can still fail to allocate storage at any point before that length is reached.
The maximum length the string can reach.
size_t is an unsigned integral type.
// comparing size, length, capacity and max_size
int main ()
std::string str ("Test string");
std::cout << "size: " << str.size() << "\n";
std::cout << "length: " << str.length() << "\n";
std::cout << "capacity: " << str.capacity() << "\n";
std::cout << "max_size: " << str.max_size() << "\n";
A possible output for this program could be:
Unspecified, but generally constant.
The object is accessed.
No-throw guarantee: this member function never throws exceptions.