C++:vector容器

二维向量的遍历方法

1
2
3
4
5
6
7
8
9
//二维向量的遍历,迭代器遍历
vector<vector<int> > array = {{1,2,8,9},{2,4,9,12},{4,7,10,13},{6,8,11,15}};
vector<vector<int >>::iterator iter;
for (iter = array.begin(); iter != array.end() ; ++iter) {
for (int i = 0; i < (*iter).size(); ++i) {
cout << (*iter)[i] << " " ;
}
cout << endl;
}
1
2
3
4
5
6
7
8
9
//二维向量的遍历,数组下表
vector<vector<int> > array = {{1,2,8,9},{2,4,9,12},{4,7,10,13},{6,8,11,15}};

for (int i = 0; i < array.size(); i++)
{
for(int j = 0; j < array[i].size(); j++)
cout << V[i][j] << " ";
cout << endl;
}
作者

John Doe

发布于

2021-02-06

更新于

2021-02-07

许可协议

You need to set install_url to use ShareThis. Please set it in _config.yml.
You forgot to set the business or currency_code for Paypal. Please set it in _config.yml.

评论