使用vector<vector<int>>实现的一个二维数组
本文为大大维原创,最早于博客园发表,转载请注明出处!!!
1 #include<iostream> 2 #include<vector> 3 using namespace std; 4 int main() 5 { 6 typedef vector<int> COL; 7 typedef vector<COL> ROW; 8 9 COL vecCol; 10 ROW vecRow; 11 int in,cCnt{0},rCnt{0}; 12 while(1) 13 { 14 while(1) 15 { 16 cout<<"input "<<rCnt<<"."<<cCnt++<<"(<0 stop):"<<endl; 17 cin>>in; 18 if(in<0)break; 19 else vecCol.push_back(in); 20 } 21 if(!vecCol.empty()) 22 { 23 vecRow.push_back(vecCol); 24 vecCol.clear(); 25 ++rCnt; 26 } 27 cCnt=0; 28 cout<<"is Continue(<0 stop):"<<endl; 29 cin>>in; 30 if(in<0)break; 31 } 32 for(auto row:vecRow) 33 { 34 for(auto col:row) 35 cout<<col<<" "; 36 cout<<endl; 37 } 38 }