c++ - 在 C++11 中初始化 std::vector<std::string> 不起作用?

标签 c++

<分区>

我的代码:

#include <vector>
std::vector<std::string> keyNamesList = { "A", "B" };

无法编译,出现错误:

No matching constructor for initialization of std::vector<std::string>

这很奇怪,因为我使用的是 C++11 (Xcode LLVM),它上面编译的行是 std::vector<int> = { 1, 2 };

这必须有效。有什么想法吗?

最佳答案

您还需要#include <string> .

关于c++ - 在 C++11 中初始化 std::vector<std::string> 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34346856/

相关文章:

c++ - 我可以在异步 io_machine 中使用阻塞 I/O 吗?

c++ - 继承自 CString 导致内存不足异常

c++ - 3D 碰撞分辨率,移动 AABB + 多面体

c++ - 如何在 C++20 'requires' 表达式中使用未指定的类型?

c++ - 如何简化这个二叉树遍历函数?

c++ - 如何在英特尔 SSE 内在函数中将参数传递给 const 值?

c++ - 如何删除双向链表数据并返回?

c++ - C++ “was not declared in this scope”编译错误和修改提示

c++ - 指向具有可变参数 number 的函数的指针

c++ - 具有平凡项(零乘积项)的 g++ 优化算术表达式