【发布时间】:2015-05-07 17:02:04
【问题描述】:
在控制台上打印出字符串向量的最简单方法是什么?
我得到了这样的东西
map < int, vector<string>>
我想将值打印到用户给定的键。
typemap::iterator p1;
cin >> i
for (pointer = map.begin(); pointer != map.end(); ++pointer)
{
if ((pointer->first) == i)
{
//The program should print the values right here.
}
}
【问题讨论】:
-
不要使用
for循环搜索map,使用map::find。map的全部意义在于通过键高效查找。 -
另外:查找 std::map 的文档(例如:en.cppreference.com/w/cpp/container/map)。或者买一本书:stackoverflow.com/questions/562303/…
标签: c++ string vector output cout