1 #include <vector>//动态数组 2 #include <iostream> 3 using namespace std; 4 vector <int> vec;//定义 5 int main(){ 6 int n; 7 cin>>n; 8 for(int i=1;i<=n;i++){ 9 vec.push_back(i);//输入 10 cout<<" "; 11 } 12 cout<<endl; 13 for(int i=0;i<n;i++){ 14 cout<<vec[i];//输出 15 cout<<" "; 16 } 17 cout<<endl; 18 //指针迭代器 19 vector <int> :: iterator it; 20 for(it=vec.begin();it!=vec.end();it++) 21 { 22 cout<<(*it)<<" "; 23 } 24 cout<<endl; 25 return 0; 26 }
标签:动态,迭代,int,vec,数组,include,指针 From: https://www.cnblogs.com/look-before-you-leap/p/17082952.html