operator==,!=,<,<=,>,>=,<=>(std::basic_string) - cppreference.com
Compare two basic_string objects
template< class CharT, class Traits, class Alloc > bool operator==( const std::basic_string<CharT,Traits,Alloc>& lhs, const std::basic_string<CharT,Traits,Alloc>& rhs );
(constexpr since C++20)
template< class CharT, class Traits, class Alloc > bool operator!=( const std::basic_string<CharT,Traits,Alloc>& lhs, const std::basic_string<CharT,Traits,Alloc>& rhs );
(noexcept since C++11)
template< class CharT, class Traits, class Alloc > bool operator<( const std::basic_string<CharT,Traits,Alloc>& lhs, const std::basic_string<CharT,Traits,Alloc>& rhs );
(noexcept since C++11)
template< class CharT, class Traits, class Alloc > bool operator<=( const std::basic_string<CharT,Traits,Alloc>& lhs, const std::basic_string<CharT,Traits,Alloc>& rhs );
(noexcept since C++11)
template< class CharT, class Traits, class Alloc > bool operator>( const std::basic_string<CharT,Traits,Alloc>& lhs, const std::basic_string<CharT,Traits,Alloc>& rhs );
(noexcept since C++11)
template< class CharT, class Traits, class Alloc > bool operator>=( const std::basic_string<CharT,Traits,Alloc>& lhs, const std::basic_string<CharT,Traits,Alloc>& rhs );
(noexcept since C++11)
template< class CharT, class Traits, class Alloc > constexpr /*comp-cat*/ operator<=>( const std::basic_string<CharT,Traits,Alloc>& lhs, const std::basic_string<CharT,Traits,Alloc>& rhs ) noexcept;
Compare a basic_string object and null-terminated array of T
template< class CharT, class Traits, class Alloc > bool operator==( const std::basic_string<CharT,Traits,Alloc>& lhs, const CharT* rhs );
template< class CharT, class Traits, class Alloc > bool operator==( const CharT* lhs, const std::basic_string<CharT,Traits,Alloc>& rhs );
template< class CharT, class Traits, class Alloc > bool operator!=( const std::basic_string<CharT,Traits,Alloc>& lhs, const CharT* rhs );
template< class CharT, class Traits, class Alloc > bool operator!=( const CharT* lhs, const std::basic_string<CharT,Traits,Alloc>& rhs );
template< class CharT, class Traits, class Alloc > bool operator<( const std::basic_string<CharT,Traits,Alloc>& lhs, const CharT* rhs );
template< class CharT, class Traits, class Alloc > bool operator<( const CharT* lhs, const std::basic_string<CharT,Traits,Alloc>& rhs );
template< class CharT, class Traits, class Alloc > bool operator<=( const std::basic_string<CharT,Traits,Alloc>& lhs, const CharT* rhs );
template< class CharT, class Traits, class Alloc > bool operator<=( const CharT* lhs, const std::basic_string<CharT,Traits,Alloc>& rhs );
template< class CharT, class Traits, class Alloc > bool operator>( const std::basic_string<CharT,Traits,Alloc>& lhs, const CharT* rhs );
template< class CharT, class Traits, class Alloc > bool operator>( const CharT* lhs, const std::basic_string<CharT,Traits,Alloc>& rhs );
template< class CharT, class Traits, class Alloc > bool operator>=( const std::basic_string<CharT,Traits,Alloc>& lhs, const CharT* rhs );
template< class CharT, class Traits, class Alloc > bool operator>=( const CharT* lhs, const std::basic_string<CharT,Traits,Alloc>& rhs );
template< class CharT, class Traits, class Alloc > constexpr /*comp-cat*/ operator<=>( const std::basic_string<CharT,Traits,Alloc>& lhs, const CharT* rhs );
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()):
1-7) Compares two basic_string objects.
8-20) Compares a basic_string object and a null-terminated array of CharT.
1-6,8-19) true if the corresponding comparison holds, false otherwise.
7,20) static_cast</*comp-cat*/>(lhs.compare(rhs) <=> 0).
Linear in the size of the strings.
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.