void print_words (const map <string, int>& printMap)
{
FOO p (printMap.size()); //create an FOO object p
p = for_each (printMap.begin(), printMap.end(), p);//call p for_each element in the map
map <string, int>::const_iterator pos;
for (pos = printMap.begin(); pos != printMap.end(); pos++)
{
cout << left << setw(ITEM_W) << pos->first << right << ": " << pos->second;
++pos;
cout << " " << left << setw(ITEM_W) << pos->first << right << ": " << pos->second;
}
}
Here is the error: "Debug assertion failed. Map/set iterator not derefencable."
I think I understand the problem: that I'm using my pos to iterator to the next map element and I'm using it with the printMap.end () function. However, I'm not sure how to get my program to do what I want, which is so output like this using a for loop, but with each iteration on the same line rather than a new line:
word : 1 word2 :1 word3: 2
Please let me know if you need anymore information. Thank you so much for the help!
I am still getting the error even after I put the newline. ne555 i know line 12 is what's causing the problems, just not sure how to get the result i need if I remove it.