how to push front in vector c++ code example
Example 1: inserting at start in vector c++
vector_name.insert(vector_name.begin(), element_to_be_inserted);
vector_name.insert(vector_name.begin()+(x-1), element_to_be_inserted);
vector_name.push_back(element_to_be_inserted);
Example 2: insert at position in vector c++
v.insert(v.begin() + i, v2[i])
Example 3: vector push front insert()
auto it = vec.insert(vec.begin(), 3);
Example 4: back_inserter in vector c++
#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm>
int main () {
std::vector<int> foo,bar;
for (int i=1; i<=5; i++)
{ foo.push_back(i); bar.push_back(i*10); }
std::copy (bar.begin(),bar.end(),back_inserter(foo));
std::cout << "foo contains:";
for ( std::vector<int>::iterator it = foo.begin(); it!= foo.end(); ++it )
std::cout << ' ' << *it;
std::cout << '\n';
return 0;
}