| |
15.7.2.string overloaded equality and relational operators |
|
#include <iostream>
using std::cout;
using std::endl;
#include <string>
using std::string;
int main()
{
string s1( "AA" );
string s2( " AAB" );
string s3;
//
cout << "s1 is \"" << s1 << "\"; s2 is \"" << s2
<< "\"; s3 is \"" << s3 << '\"'
<< "\n\nThe results of comparing s2 and s1:"
<< "\ns2 == s1 yields " << ( s2 == s1 ? "true" : "false" )
<< "\ns2 != s1 yields " << ( s2 != s1 ? "true" : "false" )
<< "\ns2 > s1 yields " << ( s2 > s1 ? "true" : "false" )
<< "\ns2 < s1 yields " << ( s2 < s1 ? "true" : "false" )
<< "\ns2 >= s1 yields " << ( s2 >= s1 ? "true" : "false" )
<< "\ns2 <= s1 yields " << ( s2 <= s1 ? "true" : "false" );
return 0;
}
|
|
s1 is "AA"; s2 is " AAB"; s3 is ""
The results of comparing s2 and s1:
s2 == s1 yields false
s2 != s1 yields true
s2 > s1 yields false
s2 < s1 yields true
s2 >= s1 yields false
s2 <= s1 yields true |
|