← From C to C++: What's New

String Equality, Revisited

hard

This is the exact same problem as Module 2’s “String Equality Without strcmp” exercise – including the same "cat" vs "cats" trap case, where every character of the shorter word matches a prefix of the longer one. There, you had to write a character-by-character loop and explicitly check that both strings hit their null terminator at the same position. Here, std::string already knows its own length (it doesn’t rely on scanning for a terminator at all), so == just works correctly, including on that trap case, with no loop of your own.

This isn’t cheating – it’s the entire point of the last lesson’s std::string section. Recognizing when a language feature has already solved a problem you’d otherwise hand-rebuild is a real skill, not a shortcut around learning.

Your solution

"Run" uses the sample stdin ("cat cat"). "Submit" checks your code against all 4 test cases.

Test results

Submit your solution to run it against all test cases.

Hints

    Reference solution