c++ - 如何计算字符串 vector ?

标签 c++ string vector output cout

在控制台上打印字符串 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/

相关文章:

c - 从 http GET 请求中用 c 进行字符串搜索

string - Unicode 字符串的固定长度存储的正确编码?

C++ 如何将数组 int[10] push_back 到 std::vector<int[10]>?

c++ - Qt 正在记住我的代码的以前版本

c# - 在 C++ 中创建原始文本字符串,类似于 C#'s "@string"

php - 在 PHP 中用 == 比较不同的字符串返回 true

r - 将命名向量转换为 R 中的列表

php - 将 c++ 函数调用到 PHP 代码中

c++ - 定义模板类的静态常量变量

c++ - 从文件读取并写入 2D vector