c++ - 如何在 C++ 中初始化 const int 二维 vector

标签 c++ data-structures vector constants

如何初始化一个 const int 二维 vector :

Const int vector < vector < int > >  v ? 

v = {1 , 1 ; 1, 0}  ?

它不起作用。

最佳答案

你可以这样做(only in C++11):

const vector<vector<int>>  v{{1,2,3},{4,5,6}};

另请注意,您无需编写 >>。由于此问题已在 C++11 中修复,因此 >>> 将起作用。它不会被解释为右移运算符(C++03 就是这种情况)。

关于c++ - 如何在 C++ 中初始化 const int 二维 vector ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8499571/

相关文章:

c++ - 模板函数特化默认参数

c++ - 在不创建新拷贝的情况下初始化成员变量

data-structures - 这种树的名字是什么(如果有的话)?

c++ - 原子变量的 vector (数组)

c++ - 在 Visual C++ 2005 中编译

c++ - 错误: reduction variable is private in outer context (omp reduction)

python - 使用 Python 的只读二进制平面文件存储选项

python - 如何在 Python 中实现二叉搜索树?

c++ - 指向包含两个 vector 的数组的指针

c++ - 如何遍历二维 vector ?