I have a map of a vector of char's and a vector of strings. Every so often, if I've seen the vector of characters before, I'd like to add a string to my vector of strings. Below is my code to do that.
map<vector<char>, vector<string>>::iterator myIter = mMyMap.find(vChars);
if(myIter != mMyMap.end()) {
vector<string> vStrings = myIter->second;
mMyMap.erase(myIter);
vStrings.push_back(some_other_string);
mMyMap.insert(pair<vector<char>, vector<string>>(vChars, vStrings));
return TRUE;
}
The call to mMyMap.erase() seems to get stuck an in infinite loop though. I'm guessing it's because vStrings isn't getting a deep-copy of myIter->second.
Do I need to initalize vStrings like:
vector<string> vStrings(myIter->second);
Or what's the proper fix?