vector2
1 #include<iostream> 2 #include<vector> 3 using namespace std; 4 void test01() 5 { 6 vector<vector<int>>v; 7 vector<int>v1; 8 vector<int>v2; 9 vector<int>v3; 10 vector<int>v4; 11 for(int i=0;i<4;i++) 12 { 13 14 v1.push_back(i+1); 15 v2.push_back(i+1); 16 v3.push_back(i+1); 17 v4.push_back(i+1); 18 } 19 //将小容器插入大容器中 20 v.push_back(v1); 21 v.push_back(v2); 22 v.push_back(v3); 23 v.push_back(v4); 24 //通过大容器,把所有数据遍历一遍 25 for(vector<vector<int>>::iterator it=v.begin();it!=v.end();it++) 26 { 27 for(vector<int>::iterator vit=(*it).begin();vit!=(*it).end();vit++) 28 { 29 30 cout<<*vit<<" "; 31 } 32 cout<<endl; 33 34 } 35 36 } 37 int main() 38 { 39 test01(); 40 system("pause"); 41 42 }