std::string提供了一种max_size()方法来确定它可以包含的最大元素数.
std::string
max_size()
但是,为了计算字符串的最大长度,程序员必须创建一个(可能是空的)字符串对象.
如果这个类不需要程序员的任何信息,为什么不能max_size()作为编译时常量?字符串是否需要某种运行时信息来计算其最大大小?
c++ string compile-time-constant
c++ ×1
compile-time-constant ×1
string ×1