我们可以在C++中将向量<string>放入列表中吗?
Can we put vector<string> to the list in C++ ?
像这样:
列表<向量<字符串>>?
如果答案是肯定的,我如何使用它来按For Cycle打印列表中的每个元素?
谢谢大家。我知道如何打印列表<int>,FOR CYCLE可以遍历它。但事实上,如果我使用FOR CYCLE和迭代器来列出<向量<string>>,我会失败的。
如果您的编译器是最新的标准:
std::list<std::vector<std::string>> lst;
for ( auto& vec : lst ) // Iterate through all std::vector's
for ( auto& str : vec ) // Iterate through all std::string's
std::cout << str << std::endl; // str is your std::string
当然这是可能的。你可以使用迭代器来打印列表中的每个元素,试试这样的方法:
list<vector<string> >::iterator it;
for(it=your_list.begin();it!=your_list.end();it++)
{
//your code to print waht you want
//it is a pointer to a vector<string>
//...
}
相关文章:
- Pybind11:将元组列表从Python传递到C++
- 从链接列表c++中删除一个项目
- 如何(从固定列表中)选择一个数字序列,该序列将与目标数字相加
- C++如何通过用户输入删除列表元素
- 读取文件的最后一行并输入到链接列表时出错
- 复制列表初始化的隐式转换的等级是多少
- LNK2038、MSVS2017 MAGMA的原因列表
- 不能在初始值设定项列表中将非常量表达式从类型 'int' 缩小到'unsigned long long'
- 没有为自己的结构调用列表推回方法
- 使用简单类型列表实现的指数编译时间.为什么
- 一对向量构造函数:初始值设定项列表与显式构造
- 标准是否使用多余的大括号(例如 T{{{10}}})定义列表初始化?
- 通过for循环使用用户输入填充列表
- C++:如何使函数只返回作为列表一部分的字符串
- 概念中的cv限定符需要表达式参数列表
- 下面是我为检测链接列表中的循环而制作的代码
- 建议在运行时将带有类实例的列表从c++导入qml
- 如何维护资源管理器项目视图中当前可见的项目列表
- EASTL矢量<向量<int>>连续的
- 在修改列表后,std :: list&lt; t&gt; :: end()的值是否会更改