在线文档教程
C++
字符串 | Strings

operators (std::basic_string)

运算符=,%21=,<,<=,>,>=%28std::basic[医]字符串%29

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)

将字符串的内容与另一个字符串或以空结尾的CharT...

所有比较都是通过compare()成员函数%28,它本身是根据Traits::compare()29%:

  • 如果两个字符串的大小都相同,则两个字符串是相等的。lhsrhs中的每个字符都是相等的。lhs中具有等效字符的rhs在同一位置。

  • 排序比较是按字典顺序进行的--通过一个等价于std::lexicographical_compare...

1-6%29比较两basic_string物品。

7-12%29比较abasic_string对象的空结束数组。CharT...

参数

lhs, rhs-strings whose contents to compare

返回值

true如果相应的比较成立,false否则。

例外

1-6%29

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

7-12%29%280%29

复杂性

在字符串的大小上是线性的。

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/string/basic[医]字符串/运算符[医]CMP