Skip to content
Related Articles

Related Articles

std::basic_string::max_size in C++
  • Difficulty Level : Medium
  • Last Updated : 12 Jun, 2019

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.

This article is contributed by Rohit Thapliyal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Attention reader! Don’t stop learning now. Get hold of all the important C++ Foundation and STL concepts with the C++ Foundation and STL courses at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :