C++ Vector: How to Add Elements
To add elements to a vector, you can use one of the following methods:
- append()
 - append()
 
std::vector<int> vec;
vec.push_back(10);
- Add the specified element to a certain location.
 - – add in
 
std::vector<int> vec = {1, 2, 3};
vec.insert(vec.begin() + 1, 5);
- Add an element to the end
 - Add an element to the end of a container
 - Append or add to the end.
 
std::vector<std::string> vec;
vec.emplace_back("hello");