Use string overloaded equality and relational operators - C++ Class

C++ examples for Class:Operator Overload

Description

Use string overloaded equality and relational operators

Demo Code

#include <iostream> 
#include <string> 
using namespace std; 

int main() //from   w  w  w .j ava2 s.  c o  m
{ 
    string s1( "happy" ); 
    string s2( " birthday" ); 
    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" ); 

}

Result


Related Tutorials