public member function
<string>

std::basic_string::max_size

size_type max_size() const;
size_type max_size() const noexcept;
返回最大尺寸
返回 basic_string 可以達到的最大長度。

由於已知的系統或庫實現限制,這是字串可以達到的最大潛在長度,但不保證物件能夠達到該長度:它仍然可能在該長度達到之前隨時無法分配儲存空間。

引數



返回值

basic_string 可以達到的最大長度。

成員型別size_type是一種無符號整型型別。

示例

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;
}

此程式的一個可能輸出是
size: 11
length: 11
capacity: 15
max_size: 4294967291


複雜度

未指定,但通常是恆定的。
常量。

迭代器有效性

沒有變化。

資料競爭

該物件被訪問。

異常安全

無異常保證:此成員函式從不丟擲異常。

另見