1. 包含一个头文件:
1 #include <vector>
2. 申明及初始化:
1 std::vector<int> first; // empty vector of ints 2 std::vector<int> second (4,100); // four ints with value 100 3 std::vector<int> third (second.begin(),second.end()); // iterating through second 4 std::vector<int> fourth (third); // a copy of third
3. 添加元素:
1 v[0] = 3; //直接赋值 2 v.insert(v.begin(),8); //在最前面的元素前插入8 3 v.insert(v.begin()+2,1); //在第二个元素前插入新元素1 4 v.insert(v.end(),3); //在末尾插入新元素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