ccplusplus.com
Learn C, C++ Concepts
Wednesday, January 11, 2012
for_each example c++
/*********************************************************************** * File : for-each.cpp * Author : Saurabh Gupta * Desc : for_each example c++ * Source : http://ccplusplus/2011/10/standard-template-library.html * Created : PM 07:11 11 January 2012 * Note : ************************************************************************/ #include <iostream> #include <vector> #include <algorithm> using namespace std; //function that prints the passed argument void print (int elem) { cout << elem << ' ' ; } int main() { vector<int> coll; //insert elements from 1 to 9 for (int i=1; i<=9; ++i) { coll.push_back(i); } //print all elements for_each (coll.begin(), coll.end(), //range print); //operation cout << endl; } /* * OUTPUT * [sgupta@rhel6x64 algorithm]$ c++ for-each.cpp -o for-each [sgupta@rhel6x64 algorithm]$ ./for-each 1 2 3 4 5 6 7 8 9 [sgupta@rhel6x64 algorithm]$ */
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