I have to write a function that takes a string and returns all the missing letters in the string. The function below seemed simple enough but it’s not returning anything. Any hints?
string getMissingLetters(const string& sentence)
{
string alphabet = "abcdefghijklmnopqrstuvwxyz";
string sent = sentence;
transform(sent.begin(), sent.end(), sent.begin(), ::tolower);
for(unsigned int i = 0; i < sent.size(); i++)
for(unsigned int j = 0; j < alphabet.size(); j++)
{
if(sent[i] == alphabet[j])
{
alphabet.erase(i);
j--;
}
}
return alphabet;
}
You need
alphabet.erase(j,1);
to erase a single character at position j.