... << "string2.compare(0, 3, string4) > 0\n";
74 }
75 else { // result < 0
76 cout << "string2.compare(0, 3, string4) < 0\n";
77 }
78 }
string1: Testing the comparison functions. string2: Hello string3: stinger string4: Hello string1 > string4 string1.compare(string2) > 0 string1.compare(2, 5, string3, 0, 5) == 0 string4.compare(0, string2.size(), string2) == 0 string2.compare(0, 3, string4) < 0
The program declares four string
s (lines 8–11) and outputs each (lines 13–14). Line 17 tests string1
against string4
for equality using the overloaded equality operator. If the condition is true
, "string1 == string4"
is output. If the condition is false
, the condition in line 20 is tested. All the string
class overloaded relational and equality operator ...
Get C++ How to Program, 10/e now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.