ccplusplus.com
Learn C, C++ Concepts
Saturday, November 26, 2011
stl set example
/*********************************************************************** * File : set1.cpp * Author : Saurabh Gupta * Desc : set example c++ * stl set c++ * Source : http://saurabhgupta0527.blogspot.com/2011/10/standard-template-library.html * Created : PM 11:48 26 November 2011 * Note : ************************************************************************/ #include
#include
int main() { //type of the collection typedef std::set
IntSet; IntSet coll; //set container for int values /* insert elements from 1 to 6 in arbitray order *- value 1 gets inserted twice */ coll.insert(3); coll.insert(1); coll.insert(5); coll.insert(4); coll.insert(1); coll.insert(6); coll.insert(2); /* print all elements *- iterate over all elements */ IntSet::const_iterator pos; for (pos = coll.begin(); pos != coll.end(); ++pos) { std::cout << *pos << ' '; } std::cout << std::endl; } /* * OUTPUT * [sgupta@rhel6x64 stl]$ c++ set1.cpp -o set1 [sgupta@rhel6x64 stl]$ ./set1 1 2 3 4 5 6 [sgupta@rhel6x64 stl]$ */
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment