operator==,!=,<,<=,>,>=(std::basic_string)
来自cppreference.com
< cpp | string | basic string
比较二个 basic_string 对象 |
||
template< class CharT, class Traits, class Alloc > bool operator==( const basic_string<CharT,Traits,Alloc>& lhs, |
(1) | |
template< class CharT, class Traits, class Alloc > bool operator!=( const basic_string<CharT,Traits,Alloc>& lhs, |
(2) | |
template< class CharT, class Traits, class Alloc > bool operator<( const basic_string<CharT,Traits,Alloc>& lhs, |
(3) | |
template< class CharT, class Traits, class Alloc > bool operator<=( const basic_string<CharT,Traits,Alloc>& lhs, |
(4) | |
template< class CharT, class Traits, class Alloc > bool operator>( const basic_string<CharT,Traits,Alloc>& lhs, |
(5) | |
template< class CharT, class Traits, class Alloc > bool operator>=( const basic_string<CharT,Traits,Alloc>& lhs, |
(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()
定义):
- 若
lhs
与rhs
的大小相等,且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) (无)
复杂度
与字符串大小成线性。