Open In App

std::basic_string::max_size in C++

Improve
Improve
Like Article
Like
Save
Share
Report

std::basic_string::max_size is used to compute the maximum number of elements the string is able to hold due to system or library implementation limitations.

size_type max_size() const;
Parameters : None
Return value : Maximum number of characters
Exceptions : None




// CPP program to compute the limit of a string
// using max_size
#include <iostream>
#include <string>
  
int main()
{
    std::string str;
      
    // Calling max_size()
    std::cout << "Maximum size of a string is " << str.max_size() << std :: endl;


Output:

Maximum size of a string is 4294967294

Note : The maximum size can depend on the compiler and system.


Last Updated : 12 Jun, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads