0
comparin two strings in c++??
explaination
7 odpowiedzi
+ 2
It's that easy:
string str1 ("Easy");
string str2 ("Foo");
if (str1.compare(str2) != 0)
// They are not equal
if(str1.compare(str1) == 0)
//Its the same
so you use the compare method of the string class. It returns an integer. (0 if they equal).
+ 1
AKCodingBlog, I do not agree with you.
I think you can't compare them with "==" simply because there is no overloading of this operator in the class string
+ 1
Oh no, I disagreed with the reason of why it is not possible, I did not say you said it was possible :)
My mistake, I was ambiguous sorry
+ 1
String class objects CAN be compared with '=='.
http://www.cplusplus.com/reference/string/string/operators/
0
A string is a char array. That's why you can not compare them with ==
Here is the specific documentation how to compare strings
http://www.cplusplus.com/reference/string/string/compare/
( GOOGLE is your friend )
0
@Baptiste E. Prunier
Please show me where I said "you can compare strings with ==" ?!
0
No problem, I am sorry too. I think the way how strings are constructed results in your argumentation about the missing overloading. Can you agree with this?