Strings

what does the error mean. My program works somewhat efficiently but it keeps giving me this error.

Error: stringToChar: string must contain exactly 1 non-whitespace character
Can you show us the code...
string disemvowel(string s){
// TODO

if (n > s.length()) {
return s;
}
char checkLetter;
string letter = s.substr(n, 1);
checkLetter = stringToChar(letter);

if(isspace())

if (isVowel(checkLetter) == 1) {
s.erase(n, 1);
}
n += 1;
return disemvowel(s);
}
stringToChar() is giving the error, we need to see the code for that.

string letter = s.substr(n, 1);
the above line does give you a string with length 1, so looking at the error message one has to presume that the character you picked out is a space!
or there is a bug in stringToChar().
stringToChar() expects a char and you're passing it a string instead.

The rest of this looks incorrect in any case, can you post a complete (and formatted) example?
@tipaye
How did you determine what stringToChar() parameters are? It's name alone implies it takes a string and returns a char.
Also, OP makes the point that this is a runtime error not compile time.
Last edited on
Topic archived. No new replies allowed.