二维Vector的初始化方法
详见代码:
方法一:
#include<iostream>
#include<vector>
void main()
{
int a = 2;
int b = 4;
//初始化方法1
//std::vector<std::vector<int>> vec(a, std::vector<int> (b)); //2行4
vector<vector<int>> vec(a, vector<int> (b));
int m = vec.size(); //实际行元素个数
int n = vec[0].size(); //实际列元素个数
}
方法二:
//初始化方法2
//std::vector<std::vector<int>> vec1 = std::vector<std::vector<int>>(a, std::vector<int>(b));
vector<vector<int>> vec1 = vector<vector<int>>(a, vector<int>(b));
方法三:
//初始化方法3
//std::vector<std::vector<int>> vec2 = std::vector<std::vector<int>>(a, std::vector<int>(b)) = { { 0, 0, 0, 0 }, { 0, 1, 2, 3 } };
vector<vector<int>> vec2 = vector<vector<int>>(a, vector<int>(b)) = { { 0, 0, 0, 0 }, { 0, 1, 2, 3 } };