C++ String Library - max_size


Advertisements

Description

It returns the maximum length the string can reach.

Declaration

Following is the declaration for std::string::max_size.

size_t max_size() const;

C++11

size_t max_size() const noexcept;

Parameters

none

Return Value

It returns the maximum length the string can reach.

Exceptions

Never throw any exceptions.

Example

In below example for std::string::max_size.

#include <iostream>
#include <string>

int main () {
   std::string str ("Sairamkrishna");
   std::cout << "max_size: " << str.max_size() << "\n";
   return 0;
}

The sample output should be like this −

max_size: 4611686018427387897
string.htm
Advertisements