c++ - How to print a nested map-map-vector -


i having issues loading , printing map-map-vector data structure. think it's on printing side, since not 100% sure how use iterators.

i created , loaded data structure store data here: (i created inner_test , myvector because looked needed them iterators. i'm not sure how iterators know inner_test , myvector part of test though.)

map<int, map<string, vector<string>>> test; map<string, vector<string>> inner_test; vector<string> myvector;  ifstream thisfile; const char *file1 = argv[1]; thisfile.open(file1); string filler;  while( thisfile >> filler ){     string sortedfiller = filler;     sort(sortedfiller.begin(), sortedfiller.end());     test[filler.length()][sortedfiller].push_back(filler); } thisfile.close(); 

i tried print this, don't think quite understand i'm doing here.

map<int, map<string, vector<string>>>::iterator itr1; map<string, vector<string>>::iterator itr2; vector<string>::iterator itr3;  for(itr1 = test.begin(); itr1 != test.end(); itr1++){     cout << itr1->first;     for(itr2 = inner_test.begin(); itr2 != inner_test.end(); itr2++){         cout << itr2->first;         for(itr3 = myvector.begin(); itr3 != myvector.end(); itr3++){             cout << *itr3;         }     }     cout << endl; } 

your inner_test, , my_vector variables empty containers, , unrelated actual std::map, want print, in way. 1 of examples how can print multidimensional container:

    // auto type automatically defines return type of test.begin () for(auto itr1 = test.begin(); itr1 != test.end(); itr1++)     {     cout << itr1->first << ' '; // add space separate entries on same line     // itr1->second represents map<string, vector<string>> stored in test.     for(auto itr2 = itr1->second.begin (); itr2 != itr1->second.end (); itr2++)         {         cout << itr2->first << ' ';         // itr2->second represents vector<string> stored in map<string, vector<string>> stored in test.         for(auto itr3 = itr2->second.begin(); itr3 != itr2->second.end(); itr3++)             {             cout << *itr3 << ' ';             }         }     cout << endl;     } 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -