+ 2
C++ - Why are strings equal, but char arrays not?
Given this code: char a[] = "abcde"; char b[] = "abcde"; string c = "abcde"; string d = "abcde"; cout << (c == d); cout << (a == b); It outputs that strings are equal, but char arrays aren't. Why?
1 Odpowiedź
+ 4
Because std::string is a class with an overloaded == operator that compares character by character.
char[] is basically just a pointer that it compares, not the characters.