stl vector
初始化
vector<int> chars(26, 0); // initialized as 26 zeros
int myints[] = {10,20,30,5,15};
std::vector<int> v(myints,myints+5);
insert- b.insert(b.end(), a.begin(), a.end())
- at
- Access element (public member function )
- front
- Access first element (public member function )
- clear
- 清空元素,但不回收空间
- Access last element (public member function )
- push_back
- Add element at the end (public member function )
- pop_back
- Delete last element (public member function )
关于capacity 和 reserve:
-
vector<int> a; cout<<a.capacity()<<endl; // 0 a.push_back(1); cout<<a.capacity()<<endl; // 1 a.push_back(1); cout<<a.capacity()<<endl; // 2 a.push_back(1); cout<<a.capacity()<<endl; // 4 a.push_back(1); cout<<a.capacity()<<endl; // 4 a.push_back(1); cout<<a.capacity()<<endl; // 8 a.reserve(33); cout<<a.capacity()<<endl; // 33 a.reserve(15); cout<<a.capacity()<<endl; // 33