Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
Strings library
char_traits
classes:
string
global functions:
getline
operator+
operator<<
operator>>
comparison operators
swap


comparison operators

function
<string>
bool operator== ( const string& lhs, const string& rhs );
bool operator== ( const char* lhs, const string& rhs );
bool operator== ( const string& lhs, const char* rhs );

bool operator!= ( const string& lhs, const string& rhs );
bool operator!= ( const char* lhs, const string& rhs );
bool operator!= ( const string& lhs, const char* rhs );

bool operator< ( const string& lhs, const string& rhs );
bool operator< ( const char* lhs, const string& rhs );
bool operator< ( const string& lhs, const char* rhs );

bool operator> ( const string& lhs, const string& rhs );
bool operator> ( const char* lhs, const string& rhs );
bool operator> ( const string& lhs, const char* rhs );

bool operator<= ( const string& lhs, const string& rhs );
bool operator<= ( const char* lhs, const string& rhs );
bool operator<= ( const string& lhs, const char* rhs );

bool operator>= ( const string& lhs, const string& rhs );
bool operator>= ( const char* lhs, const string& rhs );
bool operator>= ( const string& lhs, const char* rhs );

String comparison operators

These overloaded global operator functions perform the appropriate comparison operation, between lhs and rhs.

These function depend on the value returned by string member compare.

Parameters

lhs, rhs
Both lhs and rhs can be either a string object or a null-terminated character sequence (a c-string), although at least one of them has to be a string object. In the case of a c-string, an equivalent string object is temporarily constructed for the comparison.

Return Value

Depending on the operator, the function returns:

operatorreturns
operator==lhs.compare(rhs)==0
operator!=lhs.compare(rhs)!=0
operator<lhs.compare(rhs)<0
operator>lhs.compare(rhs)>0
operator<=lhs.compare(rhs)<=0
operator>=lhs.compare(rhs)>=0

Basic template declarations

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
template<class charT, class traits, class Allocator>
  bool operator== ( const basic_string<charT,traits,Allocator>& lhs,
                    const basic_string<charT,traits,Allocator>& rhs );
template<class charT, class traits, class Allocator>
  bool operator== ( const charT* lhs,
                    const basic_string<charT,traits,Allocator>& rhs );
template<class charT, class traits, class Allocator>
  bool operator== ( const basic_string<charT,traits,Allocator>& rhs,
                    const charT* lhs );
template<class charT, class traits, class Allocator>
  bool operator!= ( const basic_string<charT,traits,Allocator>& lhs,
                    const basic_string<charT,traits,Allocator>& rhs );
template<class charT, class traits, class Allocator>
  bool operator!= ( const charT* lhs,
                    const basic_string<charT,traits,Allocator>& rhs );
template<class charT, class traits, class Allocator>
  bool operator!= ( const basic_string<charT,traits,Allocator>& rhs,
                    const charT* lhs );
template<class charT, class traits, class Allocator>
  bool operator< ( const basic_string<charT,traits,Allocator>& lhs,
                    const basic_string<charT,traits,Allocator>& rhs );
template<class charT, class traits, class Allocator>
  bool operator< ( const charT* lhs,
                    const basic_string<charT,traits,Allocator>& rhs );
template<class charT, class traits, class Allocator>
  bool operator< ( const basic_string<charT,traits,Allocator>& rhs,
                    const charT* lhs );
template<class charT, class traits, class Allocator>
  bool operator> ( const basic_string<charT,traits,Allocator>& lhs,
                    const basic_string<charT,traits,Allocator>& rhs );
template<class charT, class traits, class Allocator>
  bool operator> ( const charT* lhs,
                    const basic_string<charT,traits,Allocator>& rhs );
template<class charT, class traits, class Allocator>
  bool operator> ( const basic_string<charT,traits,Allocator>& rhs,
                    const charT* lhs );
template<class charT, class traits, class Allocator>
  bool operator<= ( const basic_string<charT,traits,Allocator>& lhs,
                    const basic_string<charT,traits,Allocator>& rhs );
template<class charT, class traits, class Allocator>
  bool operator<= ( const charT* lhs,
                    const basic_string<charT,traits,Allocator>& rhs );
template<class charT, class traits, class Allocator>
  bool operator<= ( const basic_string<charT,traits,Allocator>& rhs,
                    const charT* lhs );
template<class charT, class traits, class Allocator>
  bool operator>= ( const basic_string<charT,traits,Allocator>& lhs,
                    const basic_string<charT,traits,Allocator>& rhs );
template<class charT, class traits, class Allocator>
  bool operator>= ( const charT* lhs,
                    const basic_string<charT,traits,Allocator>& rhs );
template<class charT, class traits, class Allocator>
  bool operator>= ( const basic_string<charT,traits,Allocator>& rhs,
                    const charT* lhs );


See also