我想用值初始化二维 vector ,它给我这个错误:
IntelliSense: initialization with '{...}' is not allowed for object of type "std::vector<std::vector<int, std::allocator<int>>, std::allocator<std::vector<int, std::allocator<int>>>>"
我在使用以下时会出现上述错误是什么?
vector<vector<int>> A =
{ { 0, 0, 0, 0, 0, 0 },
{ 0, 1, 2, 2, 4, 1 },
{ 0, 3, 4, 1, 5, 2 },
{ 0, 2, 3, 3, 2, 4 },
{ 0, 4, 1, 5, 4, 6 },
{ 0, 6, 3, 2, 1, 3 } };
最佳答案
MSVS 2012 has very little C++11 support如果我们查看链接到 MSDN 的文章
我们将看到它不支持您正在使用的初始化所需的初始化列表。
我的建议是,如果可以的话,升级你的编译器。 MSVS 2017 拥有最完整的 C++11 支持(除非在新标准中有任何重大更改)。如果您不能这样做,那么您可以使用 C++11 之前的解决方案来声明临时数组并从临时数组初始化 vector 。
关于c++ - 无法使用 Microsoft Visual Studio 2012 列出初始化 vector ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44765709/