c++ vector push front code example

Example 1: inserting at start in vector c++

// Inserting at start
vector_name.insert(vector_name.begin(), element_to_be_inserted);

// Inserting after xth element
vector_name.insert(vector_name.begin()+(x-1), element_to_be_inserted);

// Inserting at last
vector_name.push_back(element_to_be_inserted);

Example 2: insert at position in vector c++

// where v is the vector to insert, i is
// the position, and value is the value

v.insert(v.begin() + i, v2[i])

Example 3: c++ how to add something at the start of a vector

#include 

int main() {
    std::vector v{ 1, 2, 3, 4, 5 };
    v.insert(v.begin(), 6);
}

Example 4: adding element in vector c++

vector_name.push_back(element_to_be_added);