Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) ListExample1

 

Technical facts

 

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

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...

*/

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml