operator==,!=,<,<=,>,>=,<=>(std::basic_string)
| 定义于头文件 <string>
|
||
| 比较二个 basic_string 对象 |
||
| (1) | ||
| template< class CharT, class Traits, class Alloc > bool operator==( const std::basic_string<CharT,Traits,Alloc>& lhs, |
(C++14 前) | |
| template< class CharT, class Traits, class Alloc > bool operator==( const std::basic_string<CharT,Traits,Alloc>& lhs, |
(C++14 起) (C++20 前) |
|
| template< class CharT, class Traits, class Alloc > constexpr bool |
(C++20 起) | |
| (2) | ||
| template< class CharT, class Traits, class Alloc > bool operator!=( const std::basic_string<CharT,Traits,Alloc>& lhs, |
(C++14 前) | |
| template< class CharT, class Traits, class Alloc > bool operator!=( const std::basic_string<CharT,Traits,Alloc>& lhs, |
(C++14 起) (C++20 前) |
|
| (3) | ||
| template< class CharT, class Traits, class Alloc > bool operator<( const std::basic_string<CharT,Traits,Alloc>& lhs, |
(C++14 前) | |
| template< class CharT, class Traits, class Alloc > bool operator<( const std::basic_string<CharT,Traits,Alloc>& lhs, |
(C++14 起) (C++20 前) |
|
| (4) | ||
| template< class CharT, class Traits, class Alloc > bool operator>=( const std::basic_string<CharT,Traits,Alloc>& lhs, |
(C++14 前) | |
| template< class CharT, class Traits, class Alloc > bool operator>=( const std::basic_string<CharT,Traits,Alloc>& lhs, |
(C++14 起) (C++20 前) |
|
| (5) | ||
| template< class CharT, class Traits, class Alloc > bool operator>( const std::basic_string<CharT,Traits,Alloc>& lhs, |
(C++14 前) | |
| template< class CharT, class Traits, class Alloc > bool operator>( const std::basic_string<CharT,Traits,Alloc>& lhs, |
(C++14 起) (C++20 前) |
|
| (6) | ||
| template< class CharT, class Traits, class Alloc > bool operator>=( const std::basic_string<CharT,Traits,Alloc>& lhs, |
(C++14 前) | |
| template< class CharT, class Traits, class Alloc > bool operator>=( const std::basic_string<CharT,Traits,Alloc>& lhs, |
(C++14 起) (C++20 前) |
|
| template< class CharT, class Traits, class Alloc > constexpr /*comp-cat*/ |
(7) | (C++20 起) |
| 比较一个 basic_string 与 T 的空终止数组 |
||
| (8) | ||
| template< class CharT, class Traits, class Alloc > bool operator==( const std::basic_string<CharT,Traits,Alloc>& lhs, |
(C++20 前) | |
| template< class CharT, class Traits, class Alloc > constexpr bool operator==( const std::basic_string<CharT,Traits,Alloc>& lhs, |
(C++20 起) | |
| template< class CharT, class Traits, class Alloc > bool operator==( const CharT* lhs, |
(C++20 前) | |
| (9) | ||
| template< class CharT, class Traits, class Alloc > bool operator!=( const std::basic_string<CharT,Traits,Alloc>& lhs, |
(C++20 前) | |
| template< class CharT, class Traits, class Alloc > bool operator!=( const CharT* lhs, |
(C++20 前) | |
| (10) | ||
| template< class CharT, class Traits, class Alloc > bool operator<( const std::basic_string<CharT,Traits,Alloc>& lhs, |
(C++20 前) | |
| template< class CharT, class Traits, class Alloc > bool operator<( const CharT* lhs, |
(C++20 前) | |
| (11) | ||
| template< class CharT, class Traits, class Alloc > bool operator<=( const std::basic_string<CharT,Traits,Alloc>& lhs, |
(C++20 前) | |
| template< class CharT, class Traits, class Alloc > bool operator<=( const CharT* lhs, |
(C++20 前) | |
| (12) | ||
| template< class CharT, class Traits, class Alloc > bool operator>( const std::basic_string<CharT,Traits,Alloc>& lhs, |
(C++20 前) | |
| template< class CharT, class Traits, class Alloc > bool operator>( const CharT* lhs, |
(C++20 前) | |
| (13) | ||
| template< class CharT, class Traits, class Alloc > bool operator>=( const std::basic_string<CharT,Traits,Alloc>& lhs, |
(C++20 前) | |
| template< class CharT, class Traits, class Alloc > bool operator>=( const CharT* lhs, |
(C++20 前) | |
| template< class CharT, class Traits, class Alloc > constexpr /*comp-cat*/ |
(14) | (C++20 起) |
比较 string 与另一 string 或 CharT 的空终止数组的内容。
所有比较通过 compare() 成员函数进行(它自身以 Traits::compare() 定义):
- 若
lhs与rhs的大小相等,且lhs中的每个字符有在rhs中在同一位置的等价字符,则二个字符串相等。
- 顺序比较按字典序——以等价于 std::lexicographical_compare 或 std::lexicographical_compare_three_way (C++20 起)的函数进行比较。
|
三路比较运算符的返回类型( /*comp-cat*/ )为 Traits::comparison_category ,若它存在,否则为 std::weak_ordering 。 |
(C++20 起) |
basic_string 对象。basic_string 对象和 CharT 的空终止数组。参数
| lhs, rhs | - | 要比较内容的字符串 |
返回值
复杂度
与字符串大小成线性。
注解
|
若至少一个参数拥有类型 std::string 、 std::wstring 、 std::u8string 、 std::u16string 或 std::u32string ,则 |
(C++20 起) |