+ 2
What is the problem in erase function ?
the assignment is : "Use the map<string, int> STL container to count occurrences of words. Use the word as the key and the count as the value. - User should be able to enter words as desired until the word “done” is written. - After entering all words, your program should print each word with its count. - Then, erase all words that start with letter ‘a’ and print again." https://code.sololearn.com/crMHfR8jH9il/?ref=app
4 ответов
+ 2
Erasing invalidates the iterator(s).
erase returns a new and valid iterator to the next object.
This also means that you shouldn't advance the iterator when you erase or risk going over the end.
+ 1
when i run it, it give me run time error!
0
i do not run the code on sololearn, i run it on codeblocks
0
i tried to write :
Map_Words.erase(it++);
and it erase correctly but not at the same time, it need to call the function more times, but i need to erase all words from one call to the function.