1.3.3 Comparing Strings

Unlike Java, in C++ strings can be compared directly using the == sign.

if (s1 == s2) {
    cout << "Your string matches my first string, " << s1 << endl;
}

Similar to other languages, strings will only match if each character matches exactly, including case.

For example Hello will match to Hello, but not hello.

Try This Example

Comparing Strings

Last updated