#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>
#include <string>
using namespace std;
int main(void)
{
vector<string> coll;
coll.reserve(4);
coll.push_back("hey!");
coll.push_back("how");
coll.push_back("are");
coll.push_back("you!");
copy(coll.begin(), coll.end(),
ostream_iterator<string>(cout," "));
cout << endl;
cout << "coll_size: " << coll.size() << endl;
cout << "coll_capacity: " << coll.capacity() << endl;
cout << "coll_max_size: " << coll.max_size() << endl;
coll.insert(find(coll.begin(), coll.end(), "how"), "jie,");
copy(coll.begin(), coll.end(),
ostream_iterator<string>(cout," "));
cout << endl;
cout << "coll_size: " << coll.size() << endl;
cout << "coll_capacity: " << coll.capacity() << endl;
cout << "coll_max_size: " << coll.max_size() << endl;
vector<string>(coll).swap(coll);
copy(coll.begin(), coll.end(),
ostream_iterator<string>(cout," "));
cout << endl;
cout << "coll_size: " << coll.size() << endl;
cout << "coll_capacity: " << coll.capacity() << endl;
cout << "coll_max_size: " << coll.max_size() << endl;
return 0;
}
本文地址:http://com.8s8s.com/it/it26065.htm