C++ std :: string是一个容器吗?

Tim*_*Tim 7 c++ containers stdstring

对于你们中的一些人来说这可能是个简单的问题.但我想知道a std::string是否是一个容器.容器我的意思是容器,例如std::vector,std::liststd::deque.

由于std::basic_string<>接受除积分字符之外的其他类型,但也通过使用字符数组进行优化.我不清楚它属于哪个类别.

这将编译:

#include <string>
#include <iostream>

int main() {
    std::basic_string<int> int_str;
    int_str.push_back(14);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

但是通过添加这一行:

std::cout << int_str << std::endl;
Run Code Online (Sandbox Code Playgroud)

它不会.因此,通过这些事实,我可以得出结论,std :: basic_string不适用于除字符之外的其他类型.

这可能是一个奇怪的问题.我需要知道这个的原因是因为我正在研究一个框架而我仍然无法确定"字符串"会落在哪个类别中.

BoB*_*ish 9

是的,该std::basic_string模板满足了该Container概念的所有要求.但是,我认为它对所包含的类型有更强的要求.只是想弄清楚到底是什么.

(这不是Bjarne的概念.只是标准的一点标有" 23.2.1 General container requirements".)