std::basic_string<CharT,Traits,Allocator>::max_size_C++中文网

C++ 参考手册

位置:首页 > C++ 参考手册 >字符串库 >std::basic_string > std::basic_string<CharT,Traits,Allocator>::max_size

返回 string 由于保有系统或库实现限制所能保有的最大元素数,即最大 string 的 ​std::distance(begin(), end())​ 。

参数

(无)

返回值

最大字符数

复杂度

常数。

示例

#include <iostream>
#include <string>
 
int main()
{
    std::string s;
    std::cout << "Maximum size of a string is " << s.max_size() << "\n";
}

可能的输出:

Maximum size of a string is 4294967294

参阅