Comparison is always true... Why?

Here's my code.

1
2
3
4
if (letter3.compare("\n")==1){
PrintCharacterLineEnd();
return main();
cin.get();}


letter3 is a string. I want the program to do the function when letter3 contains the text "\n". However, even with letter3 is not "\n" it's doing the function.

How can I fix this?
How can I fix this?

Read the help about string::compare
http://www.cplusplus.com/reference/string/string/compare/

and then string::find
http://www.cplusplus.com/reference/string/string/find/

Both have example code.

Andy

PS And while you're there, you check out any string methods that look interesting (see the list on the lower left.)
Last edited on
Topic archived. No new replies allowed.