What I am trying to implement is a basic spell checker which reads an input text file and compares the words to a small dictionary. If the word isn't in the dictionary then it is assumed to be spelled wrong, and then the user is prompted to spell the word correctly. This correctly spelled word is stored with its misspelled counterpart in a map. So far I have been able to do all this. What I cant figure out though is how to iterate over the entire map to check if that key (misspelled word) already exists without asking the user every time how to spell it if it is not found in that iteration of the map? Below is the code i have so far which checks to see if the word is in the dictionary, asks the user how to spell it if its not, and adding it to the map.
std::map<std::string,std::string>::iterator p = m_Replacements.begin();
bool isIn = m_Dictionary.find(oneWord) != m_Dictionary.end();
std::map<std::string,std::string>::iterator found = m_Replacements.find(oneWord);
if(found==m_Replacements.end())
{
if( isIn == false)
{
osInputPrompt<<"How do you correctly spell " + oneWord + "\n";
isInputPrompt >> correctSpell;
m_Replacements.insert(make_pair(textWord,correctSpell));
osOutput<<correctSpell + " ";
}
else
{
osOutput<<oneWord + " ";
}
So in summation, I would like to add another loop inside the loop that checks if the word is in the dictionary which would then check the whole map to see if the misspelled word is already there without asking "How do you correctly spell..." for each iteration of the map loop. Just for clarification I am not asking how to iterate over a map, I already know how to do that. Thanks in advance.