-4

I am comparing two strings "Good Luck" > "Good Bye" in c++. Shouldn't the boolean result be true? The 'L' is greater than the 'B' The blank space between the words is one whitespace.

However, I am getting false with run the code.

Do you know why? Below is my code.

#include <iostream>

using namespace std;

int main()
{

    bool result = "Good Luck" > "Good Bye!";

    cout << result;

    return 0;
}
Avi
  • 507
  • 3
  • 9
  • 26

1 Answers1

0

You're comparing char*s, which is just comparing the memory addresses that the strings live at.

  • The documentation differs -- s1 > s2 : A string s1 is greater than s2 string, if either, length of s1 is longer than s2 or first mismatched character is larger – Avi Mar 25 '18 at 16:35
  • 7
    @Avi: That's the documentation for `std::string`, which you are not using. – SLaks Mar 25 '18 at 16:36
  • 3
    @Avi I repeat: Distinguish C-string and `std::string`. –  Mar 25 '18 at 16:37