codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#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; }
Private
[
?
]
Run code
Submit