- iterator insert(
- const_iterator _Where,
- const Type& _Val
- );
- iterator insert(
- const_iterator _Where,
- Type&& _Val
- );
- void insert(
- const_iterator _Where,
- size_type _Count,
- const Type& _Val
- );
- template<class InputIterator>
- void insert(
- const_iterator _Where,
- InputIterator _First,
- InputIterator _Last
- );
- void test_vector_insert()
- {
- std::vector<int> v1;
- v1.push_back(10);
- v1.push_back(20);
- v1.push_back(30);
- std::cout << "v1 = " ;
- std::copy(v1.begin(), v1.end(), std::ostream_iterator<int>(std::cout, " "));
- std::cout << std::endl;
- // 方法1:
- v1.insert(v1.begin() + 1, 40);
- std::cout << "v1 = ";
- std::copy(v1.begin(), v1.end(), std::ostream_iterator<int>(std::cout, " "));
- std::cout << std::endl;
- // 方法3:
- v1.insert(v1.begin() + 2, 4, 50);
- std::cout << "v1 = ";
- std::copy(v1.begin(), v1.end(), std::ostream_iterator<int>(std::cout, " "));
- std::cout << std::endl;
- // 方法4:
- v1.insert(v1.begin() + 1, v1.begin() + 2, v1.begin() + 4);
- std::cout << "v1 = ";
- std::copy(v1.begin(), v1.end(), std::ostream_iterator<int>(std::cout, " "));
- std::cout << std::endl;
- }