C++二维vector使用
程序员文章站
2022-05-19 10:21:48
...
记录下二维vector的遍历(输出)
注:二维vector的赋值不能跟二维数组一样用scanf或者cin写入
遍历(迭代器)
方法一
void print() {
vector<vector<char>>::iterator it;
vector<char>::iterator iter;
vector<char> ch;
for(it = res.begin(); it != res.end(); ++it) {
ch = *it;
for (iter = ch.begin(); iter != ch.end(); ++iter) {
cout << *iter << " ";
}
}
cout << endl;
}
方法二
void print() {
for (int i = 0; i < res.size(); ++i) {
for (int j = 0; j < res[0].size(); ++j) {
cout << res[i][j] << " ";
}
}
cout << endl;
}
才疏学浅,望雅正!