ccplusplus.com
Learn C, C++ Concepts
Sunday, November 20, 2011
iterator example
/*********************************************************************** * File : list2.cpp * Author : Saurabh Gupta * Desc : example demonstrating the use of iterators * iterator example c++ * Source : http://saurabhgupta0527.blogspot.com/2011/10/standard-template-library.html * Created : PM 11:34 20 November 2011 * Note : ************************************************************************/ #include <iostream> #include <list> using namespace std; int main() { list<char> coll; //list container for character elements // append elements from 'a' to 'z' for (char c='a'; c<='z'; ++c) { coll.push_back(c); } /* print all elements * - iterate over all elements */ list<char>::const_iterator pos; for (pos = coll.begin(); pos != coll.end(); ++pos) { cout << *pos << ' ' ; } cout << endl; } /* * OUTPUT * [sgupta@rhel6x64 stl]$ c++ list2.cpp -o list2 [sgupta@rhel6x64 stl]$ ./list2 a b c d e f g h i j k l m n o p q r s t u v w x y z [sgupta@rhel6x64 stl]$ */
See Also:
Standard Template Library Concepts and sample codes in C++
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment