Adding elements to arbitrary points in a vector - C++ STL

C++ examples for STL:vector

Description

Adding elements to arbitrary points in a vector

Demo Code

#include <cinttypes>
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char* argv[])
{
    vector<int32_t> stlVector {1,2,3,4,5};

    auto iterator = stlVector.begin() + 2;
    stlVector.emplace(iterator, 6);//w w  w .j  a va  2  s.c  o  m

    for (auto&& number : stlVector)
    {
        std::cout << number << std::endl;
    }

    return 0;
}

Result


Related Tutorials