Using a list to store int values - C++ STL

C++ examples for STL:list

Description

Using a list to store int values

Demo Code

#include <cinttypes>
#include <iostream>
#include <list>

using namespace std;

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

    myList.emplace_front(6);/*  w w  w.j  av a2s  . co m*/
    myList.emplace_back(7);
    auto forwardIter = myList.begin();
    ++forwardIter;
    ++forwardIter;
    myList.emplace(forwardIter, 9);

    auto reverseIter = myList.end();
    --reverseIter;
    --reverseIter;
    --reverseIter;
    myList.emplace(reverseIter, 8);

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

    return 0;
}

Result


Related Tutorials