编程语言

img owl2008

vector的size、capacity和max_size

发表于2004/10/29 15:01:00  1732人阅读

分类: boost/STL

#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;
}       

阅读全文
0 0

相关文章推荐

img
取 消
img