+ 1
String cutting off after blank space
I asked about string.find yesterday but now im having an issue where i want to find a sentence in a string so i did this int main() { string UInput; getline(cin, UInput); (code to convert it to lowercase) if (string::npos != UInput.find("celsius to farenheit")) {code to do things} } but even though i have use getline, the string.find is only finding the word celsius and is cutting off after the first word.
6 Respostas
+ 1
the find will check to see if the entire sentence you write in UInput.find(“”) is there, so the if statment there will only execute if it finds “celsius to farenheit” in the sentence you type. what are you trying to do that gives the error?
+ 1
Mooaholic i dont get an error, but when i type " celsius to farenheit ", my if statement doesnt execute. but then i changed it to just find "celsius" for testing purposes and it finds celsius but not a whole sentence
+ 1
Hazer C++ Begginer i made a example code
https://code.sololearn.com/ctHzw4Q2h3Qd/?ref=app
and if you run the program and type in
hello celsius to farenheit for example it will print it works and
if you type in just something like hello celsius it will print the it didnt work line.
+ 1
Mooaholic i think the issue may be that i changed it all to lower case so i didnt have to write 100 if statements. but whilst doing that i changed the number value of the letters (the ascii table) and it worked before, but now it doesnt. maybe thats the reason?
0
Hazer C++ Begginer maybe i dont usually change to lowercase with ascii table i have changed string numbers to int that that before. but i have updated the code i posted here with examples of the 2 lower case options i mentioned in the other question.
0
Mooaholic the example of your code worked great! thanks