Sorry for posting the same problem again, but I used the suggested solutions, and it partially worked…
So I want to clarify the problem:
So:
I defined a vector of maps, like this:
typedef vector<map<string,unsigned int> > myvec;
And a map of vectors (i called it index) like this:
typedef map<string,vector<unsigned int> > index;
Then I did the following:
In my class, called myCoogle, i declared myvec maps_vec;
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 index the_index;
Now I want to copy all the different words from the_vec to the_index.
The words will be the strings…
And for each vector i will be adding the numbers stored in the vector of maps.
For example:
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 | …
So the_index should look like this:
word,[vector of ints]
chicken[1,0,3]
person,[1,2,0]
elevator[5,0,1]
is[2,3,4]
icecream[0,3,0]
bear[0,0,1]
OK here’s my function:
void Coogle::make_index()
{
//SCAN THE FIRST MAP
myvec::iterator myvec_iter;
map<string,unsigned int>::iterator map_iter;
index::iterator idx_iter = the_index.begin();
for(map_iter=maps_vec[0].begin(); map_iter!=maps_vec[0].end(); ++map_iter)
{
the_index[map_iter->first].push_back(map_iter->second);
}
//SCAN THE OTHER MAPS
myvec_iter=maps_vec.begin();
myvec_iter++;
int i=0; //FILE #
while(myvec_iter!=maps_vec.end())
{
i++;
for(map_iter=maps_vec[i].begin(); map_iter!=maps_vec[i].end(); ++map_iter)
{
string word=map_iter->first;
cout << "DEALING WITH WORD \"" << word << "\"" << endl;
index::iterator location;
location=the_index.find(word);
if(location!=the_index.end()) //if word found in the index
{
cout << "WORD EXISTS!" << endl;
location->second[i]=map_iter->second;
}
else //if not found
{
cout << "WORD DOES NOT EXIST! NEW WORD." << endl;
the_index[word].push_back(map_iter->second);
}
}
cout << endl;
++myvec_iter;
}
}
clarification: FILE# is the maps number… I’m working with files (*.txt files).
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:

‘Build Successfully’ though.
And this window pops up when I run the program.
So I believe something is wrong with my 2nd ‘for’ loop.
Anyone can help please?
Very sorry for the very long post…
Thank you very much !!!
edit:
If I don’t try to print the_index, the program compiles and runs just fine.
But that’s not enough ofcourse.
But my print function is just alright… here:
void Coogle::print_index() const
{
index::const_iterator iter;
for(iter=the_index.begin();iter!=the_index.end();++iter)
{
cout << "Word: " << iter->first << endl;
//cout << "Files number is: " << files_number << endl; //prints: 3
for(int i=0; i<files_number;i++)
cout << "file #" << i+1 << ": " << iter->second[i] << " , " << endl;
}
}
edit:
Here’s a screen shot of printing only 1 map vs printing 3 maps:

Edit: Ok hopefully I finally understand what you’re trying to do.
It’s hard to tell since you didn’t provide the declaration of your variables (and some of them seem to be misnamed), but I think the problem is the line
location->second[i]=map_iter->second;. You are trying to access index i in the vector, but your vector isn’t actually that long.Edit: Now that I can tell what you’re actually trying to do, you’re massively overcomplicating things. You don’t need a seperate loop for the other elements at all.