C++ 数组

std::vector 是矢量数组,可以自动增长,头文件:#include <vector>

std::array  C++11中新型容器,需要指定数组的长度,头文件:#include <array>。

 1     vector<int> vInts;
 2     for(int i=0;i<10;i++)
 3     {
 4         vInts.push_back(i);
 5     }
 6     cout<<"----------"<<endl;
 7     for(vector<int>::const_iterator iterator = vInts.begin();iterator!=vInts.end();iterator++)
 8     {        
 9         cout<<*iterator<<endl;
10     }
11     cout<<"----------"<<endl;
12     for(auto vInt:vInts)
13     {        
14         cout<<vInt<<endl;
15     }
16     cout<<"----------"<<endl;    
17     array<int,10> items = {1,2,3,4,5};
18     cout<<"items size:"<<items.size()<<endl;
19     for(auto item:items)
20     {        
21         cout<<item<<endl;
22     }

 

posted @ 2015-04-07 11:01  扑通  阅读(189)  评论(0编辑  收藏  举报