(C++) ListExample1
February 24, 2017 · View on GitHub
(C++) ListExample1
Technical facts
Operating system(s) or programming environment(s)
Lubuntu 15.04 (vivid)
Qt Creator 3.1.1
- G++ 4.9.2
Libraries used:
STL: GNU ISO C++ Library, version
4.9.2
Qt project file: ./CppListExample1/CppListExample1.pro
TEMPLATE = app CONFIG += console CONFIG -= app_bundle CONFIG -= qt QMAKE_CXXFLAGS += -std=c++11 -Wall -Wextra -Weffc++ -Werror SOURCES += main.cpp
./CppListExample1/main.cpp
#include <iostream> #include <iterator> #include <list> int main() { std::list<int> my_list; //Add a two at the end my_list.push_back(2); //Add a zero at the beginning my_list.push_front(0); //Obtain an iterator to a position in between std::list<int>::iterator my_iterator = my_list.begin(); ++my_iterator; //Insert a one in between my_list.insert(my_iterator,1); //Display the list std::copy(my_list.begin(),my_list.end(), std::ostream_iterator<int>(std::cout,"\n")); } /* Screen output: 0 1 2 Press <RETURN> to close this window... */