cpp pushfront vector

cpp push_front vector Explanation

#include <iostream>
#include <vector>

int main() {
    std::vector<int> vec = {1, 2, 3, 4, 5};

    vec.insert(vec.begin(), 0);

    for (int i : vec) {
        std::cout << i << " ";
    }

    return 0;
}
  1. Include Necessary Libraries: Include the necessary libraries for input/output and vector manipulation.
  2. Create Vector: Create a vector of integers and initialize it with values 1, 2, 3, 4, and 5.
  3. Insert Element at the Beginning: Use the insert method with vec.begin() as the first argument and the value 0 as the second argument to insert 0 at the beginning of the vector.
  4. Print Vector Elements: Use a for-each loop to iterate through the elements of the vector and print each element separated by a space.
  5. Return: End the main function and return 0 to indicate successful execution.