# operator==,!=,<,<=,>,>=(std::basic_string)

From cppreference.com
< cpp‎ | string‎ | basic string

Compare two `basic_string` objects |  |
template< class CharT, class Traits, class Alloc > bool operator==( const basic_string<CharT,Traits,Alloc>& lhs, const basic_string<CharT,Traits,Alloc>& rhs ); | (1) |
template< class CharT, class Traits, class Alloc > bool operator!=( const basic_string<CharT,Traits,Alloc>& lhs, const basic_string<CharT,Traits,Alloc>& rhs ); | (2) |
template< class CharT, class Traits, class Alloc > bool operator<( const basic_string<CharT,Traits,Alloc>& lhs, const basic_string<CharT,Traits,Alloc>& rhs ); | (3) |
template< class CharT, class Traits, class Alloc > bool operator<=( const basic_string<CharT,Traits,Alloc>& lhs, const basic_string<CharT,Traits,Alloc>& rhs ); | (4) |
template< class CharT, class Traits, class Alloc > bool operator>( const basic_string<CharT,Traits,Alloc>& lhs, const basic_string<CharT,Traits,Alloc>& rhs ); | (5) |
template< class CharT, class Traits, class Alloc > bool operator>=( const basic_string<CharT,Traits,Alloc>& lhs, const basic_string<CharT,Traits,Alloc>& rhs ); | (6) |
Compare a `basic_string` object and null-terminated array of `T` |  |
template< class CharT, class Traits, class Alloc > bool operator==( const CharT* lhs, const basic_string<CharT,Traits,Alloc>& rhs ); | (7) |
template< class CharT, class Traits, class Alloc > bool operator==( const basic_string<CharT,Traits,Alloc>& lhs, const CharT* rhs ); | (7) |
template< class CharT, class Traits, class Alloc > bool operator!=( const CharT* lhs, const basic_string<CharT,Traits,Alloc>& rhs ); | (8) |
template< class CharT, class Traits, class Alloc > bool operator!=( const basic_string<CharT,Traits,Alloc>& lhs, const CharT* rhs ); | (8) |
template< class CharT, class Traits, class Alloc > bool operator<( const CharT* lhs, const basic_string<CharT,Traits,Alloc>& rhs ); | (9) |
template< class CharT, class Traits, class Alloc > bool operator<( const basic_string<CharT,Traits,Alloc>& lhs, const CharT* rhs ); | (9) |
template< class CharT, class Traits, class Alloc > bool operator<=( const CharT* lhs, const basic_string<CharT,Traits,Alloc>& rhs ); | (10) |
template< class CharT, class Traits, class Alloc > bool operator<=( const basic_string<CharT,Traits,Alloc>& lhs, const CharT* rhs ); | (10) |
template< class CharT, class Traits, class Alloc > bool operator>( const CharT* lhs, const basic_string<CharT,Traits,Alloc>& rhs ); | (11) |
template< class CharT, class Traits, class Alloc > bool operator>( const basic_string<CharT,Traits,Alloc>& lhs, const CharT* rhs ); | (11) |
template< class CharT, class Traits, class Alloc > bool operator>=( const CharT* lhs, const basic_string<CharT,Traits,Alloc>& rhs ); | (12) |
template< class CharT, class Traits, class Alloc > bool operator>=( const basic_string<CharT,Traits,Alloc>& lhs, const CharT* rhs ); | (12) |

Compares the contents of a string with another string or a null-terminated array of `CharT`.

All comparisons are done via the compare() member function (which itself is defined in terms of `Traits::compare()`):

- Two strings are equal if both the size of `lhs` and `rhs` are equal and each character in `lhs` has equivalent character in `rhs` at the same position.

- The ordering comparisons are done lexicographically -- the comparison is performed by a function equivalent to std::lexicographical_compare.

1-6) Compares two `basic_string` objects.
7-12) Compares a `basic_string` object and a null-terminated array of `CharT`.

### Parameters

lhs, rhs | - | strings whose contents to compare

### Return value

true if the corresponding comparison holds, false otherwise.

### Exceptions

1-6)

(none) | (until C++14)
`noexcept` specification: noexcept | (since C++14)

7-12) (none)

### Complexity

Linear in the size of the strings.

Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/string/basic_string/operator_cmp&oldid=91487"