Sei sulla pagina 1di 6

2013

Saket Kr. Pathak Software Developer 3D Graphics

A girl and a guy: C++ STL (Multimap)


An approach to understand Multi-Map of STL in C++ without using bigger technical terms or with a prospective of little bit entertaining instances of life going around.

A girl and a guy: C++ STL (Multimap) Hi, all it's really a long time that I was away from this all. Few days back while I was just working, I got a chance to implement Map/Multi-Map of C++ (STL). Trust me I found a cute sketch with all innocence of the bond of love within a "Couple" or more suitable word that can I choose, will be "Pair" (means both of them are just completing each other), off course in MultiMap/Map of STL.

Here, I can bet you will realize my words are not just words but it's just the voice of your heart. For the shake of trust you can execute the code snippet. You can find the technical definition of the terms all over the internet and Off-course I will not waste my time for that. I think let's change our angle of position and have a look, you will find the imprints of complete love. I don't know you had ever loved anyone or not but yes, if you have any practical experience then you can visualize the portraits more clearly. Okee, so lets have a short story about a pretty gal and a guy (ohh , you can imagine this as your friend ). In my case, the gal is so pretty that the guy never ever wishes to see her nervous, sad or tense face. As;
Saket Kr. Pathak Page 2

A girl and a guy: C++ STL (Multimap) std::string pretty_gal = "dazzling_smile"; std::string a_gentle_guy = "guy_in_love"; His just a wish to make her all happy and No-one knows how he manages all this against every odds. I don't know about the real scenario but let's create a bond within them, As; std::pair loving_couple; loving_couple = std::make_pair(pretty_gal, a_gentle_guy); Even I am lacking, the exact sentiments of the guy, but all that he need, is her happiness may be as; he wants his identification with that only. I or Any guy, just can imagine that how deeply he is attached with her and I really don't have any experience of being Gal So I think a Gal reader can visualize it some what similar. (***Note*** (for Gal): ... Can Visualize It, If they have some good coordination between heart and brain, All they lack at this point, I know It. Whatever Exceptions are always there)

So our gentle guy has mapped himself within the happiness of the gal as; std::multimap feeling_bond; feeling_bond.insert (loving_couple); Now if, you need to find the guy, you can make use of just a single reference as gal's smile; std::multimap::iterator _bond_; _bond_ = feeling_bond.find("dazzling_smile"); printf("%s for %s", _bond_->second.c_str(), _bond_->first.c_str());

Saket Kr. Pathak

Page 3

A girl and a guy: C++ STL (Multimap) And the Output window will show you a message: Output Window: "guy_in_love for dazzling_smile" Yes It may possible, that you have some or all different prospective with the concept and even with example or scenario, that I had selected. I really don't need it. And please don't try to certify this; I will hardly bother about it.

As Always I thought to express my view in favor of concept I done that, you don't like it, It's completely your choice and I will always have respect for that. Programming is just Fun If you are capable to enjoy it ... So ... Take Care ... in someone's style not mine, I used to say ... Catch you again ...

//********************************************************// The Overall code can be found as bellow and is running successfully in Win32 Console Application with VC9 in Visual Studio 2008. //********************************************************//
Saket Kr. Pathak Page 4

A girl and a guy: C++ STL (Multimap) //------------------//Code Snippet //------------------#include #include #include #include "stdafx.h" "iostream" "string" "map"

void test_func(void) { //String type Variables: Declaration and //Definition std::string pretty_gal = "dazzling_smile"; std::string a_gentle_guy = "guy_in_love"; //Declaring instance of class STL::Pair std::pair loving_couple; //Defining the instance with pair of values loving_couple = std::make_pair(pretty_gal, a_gentle_guy); //Creating containers that store elements //formed by a combination of a key and its //mapped value std::multimap feeling_bond; feeling_bond.insert(loving_couple); // Iterator is any object that, pointing //to some element in a range of elements //find ():Searches the container for an //element with a key equivalent to k and //returns an iterator to it if found
Saket Kr. Pathak Page 5

A girl and a guy: C++ STL (Multimap) std::multimap::iterator bond_itr; bond_itr = feeling_bond.find("dazzling_smile"); //Displaying your search result in output //window with its key printf("%s for %s", bond_itr>second.c_str(), bond_itr->first.c_str()); } //---------------------------//Entry Point of the Program //---------------------------int main() { test_func(); printf("\n\n\n"); return 0; }

Saket Kr. Pathak

Page 6

Potrebbero piacerti anche