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

来自cppreference.com
< cpp‎ | string‎ | basic string
 
 
 
std::basic_string
非成员函数
operator==operator!=operator<operator>operator<=operator>=
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
帮助类
推导指引(C++17)
 
比较二个 basic_string 对象
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)
比较 basic_string 对象和 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)

比较 string 与另一 string 或 CharT 的空终止数组的内容。

所有比较通过 compare() 成员函数进行(它自身以 Traits::compare() 定义):

  • lhsrhs 的大小相等,且 lhs 中的每个字符有在 rhs 中在同一位置的等价字符,则二个字符串相等。
  • 顺序比较按字典序——以等价于 std::lexicographical_compare 的函数进行比较。
1-6) 比较二个 basic_string 对象。
7-12) 比较 basic_string 对象和 CharT 的空终止数组。

目录

[编辑] 参数

lhs, rhs - 要比较内容的字符串

[编辑] 返回值

若对应比较关系成立则为 true ,否则为 false

[编辑] 异常

1-6)
(无) (C++14 前)
noexcept 规定:  
noexcept
  
(C++14 起)
7-12) (无)

[编辑] 复杂度

与字符串大小成线性。