cplusplus.com
C++ : Reference : <string> : string : max_size
 
cplusplus.com
Information
Documentation
Reference
Articles
Forum
Reference
C library:
(assert.h)
(ctype.h)
(errno.h)
(fenv.h)
(float.h)
(inttypes.h)
(iso646.h)
C library
(limits.h)
(locale.h)
(math.h)
(setjmp.h)
(signal.h)
(stdarg.h)
(stdbool.h)
(stddef.h)
(stdint.h)
(stdio.h)
(stdlib.h)
(string.h)
(tgmath.h)
(time.h)
(uchar.h)
(wchar.h)
(wctype.h)
Containers:
Containers
Input/Output:
Input/Output
Other:
Other
class templates:
basic_string
char_traits
classes:
string
u16string
u32string
wstring
functions:
stod
stof
stoi
stol
stold
stoll
stoul
stoull
to_string
to_wstring
string
string::string
string::~string
member functions:
string::append
string::assign
string::at
string::back
string::begin
string::capacity
string::cbegin
string::cend
string::clear
string::compare
string::copy
string::crbegin
string::crend
string::c_str
string::data
string::empty
string::end
string::erase
string::find
string::find_first_not_of
string::find_first_of
string::find_last_not_of
string::find_last_of
string::front
string::get_allocator
string::insert
string::length
string::max_size
string::operator+=
string::operator=
string::operator[]
string::pop_back
string::push_back
string::rbegin
string::rend
string::replace
string::reserve
string::resize
string::rfind
string::shrink_to_fit
string::size
string::substr
string::swap
member constants:
string::npos
non-member overloads:
getline (string)
operator+ (string)
operator<< (string)
operator>> (string)
relational operators (string)
swap (string)


string::max_size

public member function
<string>
[C++98]
size_t max_size() const;
[C++11]
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.

Parameters

none

Return Value

The maximum length the string can reach.

size_t is an unsigned integral type.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
// comparing size, length, capacity and max_size
#include <iostream>
#include <string>

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";
  return 0;
}


A possible output for this program could be:
size: 11
length: 11
capacity: 15
max_size: 4294967291

Complexity

<case label="C++98">
Unspecified, but generally constant.
</case>
<case label="C++11">
Constant.
</case>

Iterator validity

No changes.

Data races

The object is accessed.

Exception safety

No-throw guarantee: this member function never throws exceptions.

See also