【问题标题】:What are the STL string limits?STL 字符串限制是什么?
【发布时间】:2009-10-05 17:14:17
【问题描述】:

C++ 中标准模板库的字符串限制是什么?

【问题讨论】:

  • 你的意思是“限制”,大小限制对吗?

标签: c++ string


【解决方案1】:
#include <iostream>
#include <string>

int main() {
    std::cout << std::string().max_size() << std::endl;
    return 0;
}

【讨论】:

  • 是的,有趣的是std::string::allocator_type().max_size() 给出了不同的(更大的)答案。不知道为什么会这样..
  • 分配器max_size()的具体语义相当模糊。
  • @Pavel:同意,但 std::allocator 应该返回“理论上我可以连续分配多少个 T”。在我的系统上这是size_type(-1)...但是std::string::max() 大约是它的四分之一,这看起来很奇怪,它会如此保守。我的意思是,如果分配器说它可能可以,为什么不尝试让它失败并使用std::length_error(无论如何都会这样)?
猜你喜欢
  • 1970-01-01
  • 2015-10-25
  • 1970-01-01
  • 2013-11-12
  • 2019-01-06
  • 2012-03-31
  • 2016-09-15
  • 1970-01-01
  • 2015-08-15
相关资源
最近更新 更多