C++ World

C++ Resources, Tips,
Documentation, Examples,
HOWTO's, FAQ's, Tools
Libraries, Frameworks, IDE's

 
© 2005,2009 C++ World - All rights reserved - webdesign.arttina
C++, Sockets, SysProg, Libraries, Examples, Tools, Compilers, IDE, STL, XML
Google
FAQ Sockets Socket Library Software Engineering Sysprog Examples Books
 
Home
C++
The C Language
STL
BOOST
GNU
GNU C Compiler
GNU Debugger
GNU Profiler
HP C++ Compiler
DDD
Eclipse
Curses
XML
X11
KDevelop
MS Visual Studio
Tutorials
// *************************************************
// File: list2.cpp
// Author: franzbrandel@cplusplusworld.com
// (c) 2009 C++ World
// http://www.cplusplusworld.com/
// simple example
// *************************************************

#include <iostream>
#include <list>
#include <vector>
#include <string>
 
// This example shows how easy lists can be filled
// This time, we do not empty the list, but show the
// application of an iterator, by iterating through
// the list
// NOTE! The list is not empty at the end of the execution.
// We only walk through the list.


int main(int argc, char *argv[]) {
 std::list<std::string> l;      
 std::vector<std::string> v;
 std::list<std::string>::const_iterator iter;

 v.push_back("first");
 v.push_back("second");
 v.push_back("third");

 // List elements are added to the end 
 for ( int i = 0; i < 10 ; ++i ) {
  l.push_back( v[ i % 3 ] );
 }
	
 for (iter = l.begin(); iter != l.end(); ++iter) {
 	std::cout << *iter << '\n';
 }
 
 return 0;
}


syntax highlighted by Code2HTML, v. 0.9.1


Franz Brandel Contact Legal Statement Sitemap C++ World