UIU: Learn C++ STL by Examples : Map



// @BEGIN_OF_SOURCE_CODE

#include <cstdio>
#include <map>
#include <string>

using namespace std;

int main (int argc, char *argv [])
{
    map <string, int> mp;

    mp ["Hello"] = 11;
    mp ["UIU"] = 22;
    mp ["C++"] = 33;

    if (mp ["C++"]) {
        printf ("%d\n", mp ["C++"]);
    }

    mp ["Zero"] = 0;

    if (mp ["Zero"]) {
        printf ("%d\n", mp ["Zero"]);
    }

    if (mp.find("Zero") != mp.end()) {
        printf ("%d\n", mp ["Zero"]);
    }

    mp.erase(mp.find("C++"));

    printf ("%lu\n", mp.size());

    return 0;
}

// @END_OF_SOURCE_CODE

One thought on “UIU: Learn C++ STL by Examples : Map

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s