Declare map that holds key/value pairs in which the key is a string and the value is an int. - C++ STL

C++ examples for STL:map

Description

Declare map that holds key/value pairs in which the key is a string and the value is an int.

Demo Code

#include <iostream>
#include <string>
#include <map>
using namespace std;
void show(const char *msg, map<string, int> mp);
int main() {//from ww  w . j  a v  a  2s .  c om
   // Declare an empty map that holds key/value pairs
   // in which the key is a string and the value is an int.
   map<string, int> m;
   // Insert characters into m. An iterator to the inserted
   // object is returned.
   m.insert(pair<string, int>("Alpha", 100));
   m.insert(pair<string, int>("Gamma", 300));
   m.insert(pair<string, int>("Beta", 200));
   return 0;
}

Related Tutorials