#include<iostream> #include<vector> int main(){ std::vector<int> arr(5); // 创建一维数组 for(int i=0;i<5;++i) std::cout << arr[i]<<" "; std::cout << std::endl; std::cout << std::endl; std::vector<int> arr1(10,90); for(std::vector<int>::const_iterator i=arr1.begin();i!=arr1.end();++i){ std::cout << *i<<" "; } std::cout << std::endl; std::cout << std::endl; std::vector<std::vector<int>> arr2(4,std::vector<int>(5,20)); // 创建二维数组 for(int i=0;i<4;++i){ for(int j=0;j<5;++j) std::cout << arr2[i][j]<<" "; std::cout <<std::endl; } std::cout << std::endl; std::vector<std::vector<int>>::iterator toarr2; std::vector<int>::iterator it; for(toarr2 =arr2.begin(); toarr2 != arr2.end(); ++toarr2){ for(it=(*toarr2).begin(); it != (*toarr2).end();++it){ std::cout << *it<<" "; } std::cout << std::endl; } std::cout << std::endl; return 0; }