在控制台上打印字符串 vector 的最简单方法是什么?
我有这样的东西
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.
}
}
最佳答案
有一个循环。并且不要遍历映射来查找键。
auto found = map.find(i);
if (found != map.end()) {
for (string const & s : found->second) {
cout << s << ' ';
}
}
关于c++ - 如何计算字符串 vector ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30107467/