1. 包含一个头文件:
1 #include <vector>
2. 申明及初始化:
std::vector<int> first; // empty vector of ints
std::vector<int> second (,); // four ints with value 100
std::vector<int> third (second.begin(),second.end()); // iterating through second
std::vector<int> fourth (third); // a copy of third
3. 添加元素:
v[] = ; //直接赋值
v.insert(v.begin(),); //在最前面的元素前插入8
v.insert(v.begin()+,); //在第二个元素前插入新元素1
v.insert(v.end(),); //在末尾插入新元素1
4. 删除元素:
5. 访问元素:
6. member functions:
vector::assign
vector::at
vector::back
vector::begin
vector::capacity
vector::cbegin
vector::cend
vector::clear
vector::crbegin
vector::crend
vector::data
vector::emplace
vector::emplace_back
vector::empty
vector::end
vector::erase
vector::front
vector::get_allocator
vector::insert
vector::max_size
vector::operator=
vector::operator[]
vector::pop_back
vector::push_back
vector::rbegin
vector::rend
vector::reserve
vector::resize
vector::shrink_to_fit
vector::size
vector::swap