Initializing a two dimensional std::vector
来源:互联网 发布:unity3d麻将开发思路 编辑:程序博客网 时间:2024/06/05 01:21
Definition:std::vector< std::vector <int> > fog;
Initialization:
not good one
for(int i=0; i<A_NUMBER; i++) { std::vector <int> fogRow; for(int j=0; j<OTHER_NUMBER; j++) { fogRow.push_back( 0 ); } fog.push_back(fogRow); }
recommend:
Use the std::vector::vector(count, value) constructor that accepts an initial size and a default value:
std::vector<std::vector<int>> fog( A_NUMBER, std::vector<int>(OTHER_NUMBER)); // Defaults to zero initial value
If a value other zero, say 4 for example, was required to be the default then:
std::vector<std::vector<int>> fog( A_NUMBER, std::vector<int>(OTHER_NUMBER, 4));
And just to mention uniform initialization introduced in c++11, which permits the initialization of vector, and other containers, using {}:
std::vector<std::vector<int>> fog { { 1, 1, 1 }, { 2, 2, 2 } };
0 0
- Initializing a two dimensional std::vector
- list initializing a vector demo
- Exchange the numbers of row and array of a two-dimensional array, and form a new two-dimensional ar
- 9. 4. 1. 二维数组矩阵 Initialize a two-dimensional array in matrix
- std::vector
- std vector
- std::vector
- std::vector
- std::vector
- std::vector
- std::vector
- std::vector
- std::vector
- std::vector
- std::vector
- A Bug which is not a std::vector bug
- Initializing a Build Environment
- Initializing a Build Environment
- 连接github Permission denied (publickey).解决
- 二叉树的创建
- MAC-Mac OS Terminal 笔记1
- Unreal Open Day 2017 参会总结——NVIDA GameWorks 在UE4中的应用
- 关于双向队列
- Initializing a two dimensional std::vector
- 百度定位
- java中给出一个多线程TCP的ServerSocket例子?
- 【JavaScript】(6)Object、String、Array、Date对象的方法、属性(constructor、prototype)
- 深入PHP面向对象、模式与实践——企业模式
- 爬虫入门(二)让爬虫健壮起来
- WINDOWS PE制作
- yolo训练自己的数据实践总结
- Elton John ------Sorry seems to be the hardest