String comparison

Apr 10, 2013 at 9:47pm
I know that you can use the compare.string function to compare two strings. I also know through my own playing around that you can compare two strings using the == operator. Is there any reason why I shouldn't be using == to compare strings?
Apr 10, 2013 at 9:56pm
operator == only reports whether two objects of type std::string are equal to each other. If you need to know which string is greater or less than other if they are inequal then it is better to use function compare.
Apr 10, 2013 at 10:42pm
If == works for what you need, there is no reason not to use it. Compare offers a lot more flexibility, mainly the ability to compare strings inside of strings:
http://www.cplusplus.com/reference/string/string/compare/
Apr 11, 2013 at 3:04pm
I've been using == to check if user input is the same as predefined strings, and using compare when I need to compare specific parts of strings to each other. Sounds like I'm doing alright then. Thanks for the replies.
Topic archived. No new replies allowed.