#include#include int main() { std::vector myVector {1, 3, 4, 5}; myVector.insert(myVector.begin() + 2, 2); for(int i : myVector) std::cout << i << " "; // Output: 1 3 2 4 5 return 0; }
#includeIn this example, the insert function is used to insert three elements {2, 2, 2} at position 2. The output shows a modified vector with the inserted elements. Package library: Standard Template Library (STL) - vector header.#include int main() { std::vector myVector {1, 3, 4, 5}; myVector.insert(myVector.begin() + 2, {2, 2, 2}); for(int i : myVector) std::cout << i << " "; // Output: 1 3 2 2 2 4 5 return 0; }