cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Windows Programming
Comparison is always true... Why?
Comparison is always true... Why?
Jul 3, 2013 at 8:32am UTC
CPPNoob2013
(12)
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?
Jul 3, 2013 at 8:46am UTC
andywestken
(4087)
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
Jul 3, 2013 at 9:19am UTC
Topic archived. No new replies allowed.