Iterating through a vector of maps and a map of vectors...
Hey guys get this...
I defined a vector of maps, like this:
And a map of vectors (i called it index) like this:
typedef vector<map<string,unsigned int> > myvec;
Then I did the following:
typedef map<string,vector<unsigned int> > index;
In my class, called myCoogle, i declared and I filled it with maps...
In each map there's a word (string) and a number (unsinged int).
So far so good.
I declared also Now I want to copy all the different words from maps_vec to the_index.
The words would be the strings...
And for each vector<int> i will be adding the numbers stored in the vector of maps.
the_vec has 3 maps.
the 1st has: chicken,1 | person,1 | elevator,5 | is,2 | ...
the 2nd has: person,2 | icecream,3 | is,3 | ...
the 3rd has: elevator,1 | bear,1 | is,4 |chicken,3 | ...
*the words might be similar...
So the_index should look like this:
word,[vector of ints]
OK here's my function:
clarification: FILE# is the maps number... I'm working with files (*.txt files).
//SCAN THE FIRST MAP
map<string,unsigned int>::iterator map_iter;
index::iterator idx_iter = the_index.begin();
for(map_iter=maps_vec.begin(); map_iter!=maps_vec.end(); ++map_iter)
//SCAN THE OTHER MAPS
int i=0; //FILE #
for(map_iter=maps_vec[i].begin(); map_iter!=maps_vec[i].end(); ++map_iter)
cout << "DEALING WITH WORD \"" << word << "\"" << endl;
if(location!=the_index.end()) //if word found in the index
cout << "WORD EXISTS!" << endl;
else //if not found
cout << "WORD DOES NOT EXIST! NEW WORD." << endl;
cout << endl;
Alright so after I scanned the first map, I tried to print the_index and all was fine.
But I get this when trying to print after scanning also the other maps:
So something is wrong with my 2nd 'for' loop.
Anyone can help please?
Very sorry for the very long post...
Thank you very much !!!