ccplusplus.com
Learn C, C++ Concepts
Sunday, November 27, 2011
stl multimap example
/*********************************************************************** * File : multimap.cpp * Author : Saurabh Gupta * Desc : multimap example c++ * stl multimap c++ * Source : http://saurabhgupta0527.blogspot.com/2011/10/standard-template-library.html * Created : AM 12:31 27 November 2011 * Note : ************************************************************************/ #include
#include
#include
using namespace std; int main() { //type of the collection typedef multimap
IntStringMMap; IntStringMMap coll; //set container for int/string values //insert some elements in arbitrary order //- a value with key 1 gets inserted twice coll.insert(make_pair(5,"tagged")); coll.insert(make_pair(2,"a")); coll.insert(make_pair(1,"this")); coll.insert(make_pair(4,"of")); coll.insert(make_pair(6,"strings")); coll.insert(make_pair(1,"is")); coll.insert(make_pair(3,"multimap")); /* print all element values *- iterate over all elements *- element member second is the value */ IntStringMMap::iterator pos; for (pos = coll.begin(); pos != coll.end(); ++pos) { cout << pos->second << ' '; } cout << endl; } /* * OUTPUT * [sgupta@rhel6x64 stl]$ c++ multimap.cpp -o multimap [sgupta@rhel6x64 stl]$ ./multimap this is a multimap of tagged strings [sgupta@rhel6x64 stl]$ */
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment