vector
二维数组不可以使用基于范围的for
循环遍历吗?
Code
#include<iostream>
#include<vector>
#include<algorithm>
using std::cin;
using std::cout;
using std::vector;
int main()
{
int n,m,t;
vector<vector<int>> V;
cin>>n>>m;
V.resize(n);
for(auto i:V)
{
for(int j=0;j<m;++j)
{
cin>>t;
i.push_back(t);
}
}
for(auto i:V)
{
for(auto j:i)
cout<<j<<" ";
cout<<"\n";
}
return 0;
}
IN
5 5
4 2 3 1 5
10 9 8 7 6
11 12 13 14 15
20 30 20 20 30
50 50 50 50 50
OUT