[ create a new paste ] login | about

Link: http://codepad.org/rg1CZlFY    [ raw code | output | fork ]

C++, pasted on Jan 5:
#include <iostream>
#include <vector>
#include <map>
#include <string>

using namespace std;

int main() {

  typedef vector<string> vector_str_t;
  map<string, vector_str_t> a_map;
  typedef map<string, vector_str_t>::iterator it_t;
  string str = "A String";
  vector<string> vct;
  pair<it_t, bool> pr = a_map.insert(make_pair(str, vct));
  pr.first->second.push_back("#1");
  pr.first->second.push_back("#2");
  pr.first->second.push_back("#3");
  str = "A String 2";
  pair<it_t, bool> pr2 = a_map.insert(make_pair(str, vct));
  pr2.first->second.push_back("#4");
  pr2.first->second.push_back("#5");
  pr2.first->second.push_back("#6");
  str = "A String 3";
  pair<it_t, bool> pr3 = a_map.insert(make_pair(str, vct));
  pr3.first->second.push_back("#7");
  pr3.first->second.push_back("#8");
  pr3.first->second.push_back("#9");
  
  for (it_t it = a_map.begin(); it != a_map.end(); it++) {
       cout<< "Current element of map:\n\n"
                << "Key contains: " << it->first << endl;
       cout<< "Mapped value contains: ";
       vector<string> vct = it->second;
       for (unsigned int i = 0; i < vct.size(); i++) {
            if (i != 0) 
                cout<< "\t\t       ";
            cout<< vct.at(i) <<endl;
       }
  }

   return 0;

}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Current element of map:

Key contains: A String
Mapped value contains: #1
		       #2
		       #3
Current element of map:

Key contains: A String 2
Mapped value contains: #4
		       #5
		       #6
Current element of map:

Key contains: A String 3
Mapped value contains: #7
		       #8
		       #9


Create a new paste based on this one


Comments: