您的位置:首页 > 其它

Construct vector (构建vector)

2016-07-04 20:26 239 查看
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
//简单地说,vector是一个能够存放任意类型的动态数组,能够增加和压缩数据。
// constructors used in the same order as described above:
vector<int> first;                                // empty vector of ints
vector<int> second (4,100);                       // four ints with value 100
vector<int> third (second.begin(),second.end());  // iterating through second
vector<int> fourth (third);                       // a copy of third

// the iterator constructor can also be used to construct from arrays:
int myints[] = {16,2,77,29};
vector<int> fifth (myints, myints + sizeof(myints) / sizeof(int) );

cout<<"The content of first are:";
for(vector<int>::iterator it = first.begin(); it!=first.end();++it)
cout<<" "<<*it;
cout<<"\n" ;

cout<<"The content of second are:";
for(vector<int>::iterator it = second.begin(); it!=second.end();++it)
cout<<" "<<*it;
cout<<"\n" ;

cout<<"The content of third are:";
for(vector<int>::iterator it = third.begin(); it!=third.end();++it)
cout<<" "<<*it;
cout<<"\n" ;

cout<<"The content of fourth are:";
for(vector<int>::iterator it = fourth.begin(); it!=fourth.end();++it)
cout<<" "<<*it;
cout<<"\n" ;

cout << "The contents of fifth are:";
for (vector<int>::iterator it = fifth.begin(); it != fifth.end(); ++it)
cout << ' ' << *it;
cout <<"\n";

return 0;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: