ccplusplus.com
Learn C, C++ Concepts
Sunday, January 8, 2012
reverse iterator stl example
/*********************************************************************** * File : reverse-iterator.cpp * Author : Saurabh Gupta * Desc : c++ reverse iterator stl example * Source : http://ccplusplus/2011/10/standard-template-library.html * Created : PM 11:16 08 January 2012 * Note : ************************************************************************/ #include <iostream> #include <vector> #include <algorithm> #include <iterator> using namespace std; int main() { vector<int> coll; //insert elements from 1 to 9 for (int i=1; i<=9; ++i) { coll.push_back(i); } //print all element in reverse order copy (coll.rbegin(), coll.rend(), //source ostream_iterator<int> (cout," ")); //destination cout << endl; return 0; } /* * OUTPUT * [sgupta@rhel6x64 stl]$ c++ reverse-iterator.cpp -o reverse-iterator [sgupta@rhel6x64 stl]$ ./reverse-iterator 9 8 7 6 5 4 3 2 1 [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