public member function
<string>

std::string::max_size

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

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

引數



返回值

字串可以達到的最大長度。

size_t 是一個無符號整數型別(與成員型別 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


複雜度

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

迭代器有效性

沒有變化。

資料競爭

該物件被訪問。

異常安全

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

另見