首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::basic_string_view::compare

constexpr int compare(basic_string_view v) const;

(1)

(since C++17)

constexpr int compare(size_type pos1, size_type count1, basic_string_view v) const;

(2)

(since C++17)

constexpr int compare(size_type pos1, size_type count1, basic_string_view v, size_type pos2, size_type count2) const;

(3)

(since C++17)

constexpr int compare(const CharT* s) const;

(4)

(since C++17)

constexpr int compare(size_type pos1, size_type count1, const CharT* s) const;

(5)

(since C++17)

constexpr int compare(size_type pos1, size_type count1, const CharT* s, size_type count2) const;

(6)

(since C++17)

比较两个字符序列。

1%29长度rlen要比较的序列中,较小的size()v.size()函数通过调用traits::compare(data(), v.data(), rlen),并根据下表返回一个值:

Condition

Result

Return value

Traits::compare(data(), v.data(), rlen) < 0

this is less than v

<0

Traits::compare(data(), v.data(), rlen) == 0

size() < v.size()

this is less than v

<0

size() == v.size()

this is equal to v

​0​

size() > v.size()

this is greater than v

0

Traits::compare(data(), v.data(), rlen) > 0

this is greater than v

0

2%29相当于substr(pos1, count1).compare(v)...

3%29相当于substr(pos1, count1).compare(v.substr(pos2, count2))...

4%29相当于compare(basic_string_view(s))...

5%29相当于substr(pos1, count1).compare(basic_string_view(s))...

6%29相当于substr(pos1, count1).compare(basic_string_view(s, count2))...

参数

v

-

view to compare

s

-

pointer to the character string to compare to

count1

-

number of characters of this view to compare

pos1

-

position of the first character in this view to compare

count2

-

number of characters of the given view to compare

pos2

-

position of the first character of the given view to compare

返回值

如果此视图小于其他字符序列,则为负值;如果两个字符序列相等,则为零;如果此视图大于其他字符序列,则为正值。

例外

1%29

noexcept规格:

noexcept

复杂性

1%~29线性在字符数比较。

另见

operator==operator!=operator<operator>operator<=operator>=

lexicographically compares two string views (function template)

代码语言:txt
复制
 © cppreference.com

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

扫码关注腾讯云开发者

领取腾讯云代金券