比较(compare)
语法:
int compare( const basic_string &str ); int compare( const char *str ); int compare( size_type index, size_type length, const basic_string &str ); int compare( size_type index, size_type length, const basic_string &str, size_type index2, size_type length2 ); int compare( size_type index, size_type length, const char *str, size_type length2 ); |
compare()函数以多种方式比较本字符串和str,返回:
返回值 | 情况 |
---|---|
小于零 | this < str |
零 | this == str |
大于零 | this > str |
不同的函数:
- 比较自己和str,
- 比较自己的子串和str,子串以index索引开始,长度为length
- 比较自己的子串和str的子串,其中index2和length2引用str,index和length引用自己
- 比较自己的子串和str的子串,其中str的子串以索引0开始,长度为length2,自己的子串以index开始,长度为length
相关主题: