C ++在std :: pair内部返回列表 [英] C++ Return list inside a std::pair

查看:125
本文介绍了C ++在std :: pair内部返回列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 std :: list 中的几个元素。我必须输出像 std :: pair< int,std :: list< std :: string> > 。对于int我只是直接添加int变量到对。有没有办法在一个语句打印列表,而不必使用迭代器?

I have several elements held in a std::list. I have to output something like std::pair<int, std::list<std::string> >. For the int I just add the int variable in directly to the pair. Is there any way to print the list in one statement without having to use iterators? How do you do that inside a pair?

推荐答案


有什么办法打印列表一个语句,而不必使用interator。

Is there any way to print the list in one statement without having to use interators.

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

There sure is: If, while modifying the list, you maintain an array where you store pointers to each element contained in the list, then you can simply loop over the array to get all the objects. No need for iterators!

一个更严肃的建议:只需使用迭代器。如果您使用基于范围的循环,则不需要明确使用它们。

A more serious suggestion: Just use iterators. There's no need to use them explicitly, if you use a range based loop.

这篇关于C ++在std :: pair内部返回列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆