复制代码
vector<int> v;
v.push_back(1);
v.push_back(2);
v.push_back(3);
vector<int>::reverse_iterator it;
for(it = v.rbegin();it!=v.rend();it++){
cout << *it << "t";
}
cout << endl;
vector<int> v;
v.push_back(1);
cout << v.capacity() << endl; // 1
v.push_back(2);
cout << v.capacity() << endl; // 2
v.push_back(3);
cout << v.capacity() << endl; // 4
vector<int>::iterator it;
for(it = v.begin();it!=v.end();it++){
cout << *it << "t";
}
v.clear();
for(it = v.begin();it!=v.end();it++){
cout << *it << "t";
}
cout << endl;
vector<int> v;
v.push_back(1);
v.push_back(2);
v.push_back(3);
if(!v.empty()){
cout << "v is not empty!" << endl;
}
vector<int> v;
v.push_back(1);
v.push_back(2);
v.push_back(3);
v.erase(v.begin());
vector<int> v;
v.push_back(1);
v.push_back(2);
v.push_back(3);
v.erase(v.begin(),v.end());
c.front()返回第一个数据。
vector<int> v;
v.push_back(1);
v.push_back(2);
v.push_back(3);
if(!vec.empty()){
cout << “the first number is:” << v.front() << endl;
vector<int> v;
v.push_back(1);
v.push_back(2);
v.push_back(3);
vector<int>::reverse_iterator it;
for(it = v.rbegin();it!=v.rend();it++){
cout << *it << "t";
}
cout << endl;
c.capacity()返回容器中数据个数,翻倍增长。
复制代码vector<int> v;
v.push_back(1);
cout << v.capacity() << endl; // 1
v.push_back(2);
cout << v.capacity() << endl; // 2
v.push_back(3);
cout << v.capacity() << endl; // 4
c.clear()移除容器中的所有数据。
复制代码
vector<int>::iterator it;
for(it = v.begin();it!=v.end();it++){
cout << *it << "t";
}
v.clear();
for(it = v.begin();it!=v.end();it++){
cout << *it << "t";
}
cout << endl;
c.empty()判断容器是否为空。
复制代码
vector<int> v;
v.push_back(1);
v.push_back(2);
v.push_back(3);
if(!v.empty()){
cout << "v is not empty!" << endl;
}
c.erase(pos)删除pos位置的数据,传回下一个数据的位置。
复制代码vector<int> v;
v.push_back(1);
v.push_back(2);
v.push_back(3);
v.erase(v.begin());
c.erase(beg,end)删除[beg,end)区间的数据,传回下一个数据的位置。
复制代码vector<int> v;
v.push_back(1);
v.push_back(2);
v.push_back(3);
v.erase(v.begin(),v.end());
c.front()返回第一个数据。
c.back()传回最后一个数据,不检查这个数据是否存在。
复制代码vector<int> v;
v.push_back(1);
v.push_back(2);
v.push_back(3);
if(!vec.empty()){
cout << “the first number is:” << v.front() << endl;










