Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/143.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;std::pair中的返回列表_C++_List_Stdlist - Fatal编程技术网

C++ C++;std::pair中的返回列表

C++ C++;std::pair中的返回列表,c++,list,stdlist,C++,List,Stdlist,我在std::list中保存了几个元素。我必须输出类似于std::pair的内容。对于int,我只是将int变量直接添加到该对中。有没有办法在一条语句中打印列表而不必使用迭代器?你是如何在一双鞋里做到这一点的 是否有任何方法可以在一条语句中打印列表,而不必使用interator 确实是这样的:如果在修改列表时,您维护一个数组,其中存储指向列表中包含的每个元素的指针,那么您可以简单地在数组上循环以获取所有对象。不需要迭代器 更严肃的建议是:只使用迭代器。如果使用基于范围的循环,则无需显式使用它们。

我在
std::list
中保存了几个元素。我必须输出类似于
std::pair
的内容。对于int,我只是将int变量直接添加到该对中。有没有办法在一条语句中打印列表而不必使用迭代器?你是如何在一双鞋里做到这一点的

是否有任何方法可以在一条语句中打印列表,而不必使用interator

确实是这样的:如果在修改列表时,您维护一个数组,其中存储指向列表中包含的每个元素的指针,那么您可以简单地在数组上循环以获取所有对象。不需要迭代器


更严肃的建议是:只使用迭代器。如果使用基于范围的循环,则无需显式使用它们。

为什么不使用迭代器?您可以
复制到
ostream\u迭代器
…以便打印列表。作为一对元素的列表仍然是一个列表,与任何其他列表没有区别。为什么要提到配对?
for(auto&str:pair.second){std::cout这与配对有什么关系?