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

std::basic_string::find_last_of

size_type find_last_of( const basic_string& str, size_type pos = npos ) const;

(1)

size_type find_last_of( const CharT* s, size_type pos, size_type count ) const;

(2)

size_type find_last_of( const CharT* s, size_type pos = npos ) const;

(3)

size_type find_last_of( CharT ch, size_type pos = npos ) const;

(4)

size_type find_last_of( std::basic_string_view<CharT, Traits> sv, size_type pos = npos) const

(5)

(since C++17)

查找与给定字符序列中的一个字符相等的最后一个字符。未指定精确搜索算法。搜索只考虑间隔。0;pos如果字符不在间隔中,npos会被归还。

1%29查找最后一个字符,该字符与str...

2%29发现最后一个字符等于第一个字符中的一个。count所指向的字符串的字符。s...s可以包含空字符。

3%29查找最后一个字符,该字符与s字符串的长度由第一个空字符决定。

4%29找到最后一个等于ch...

5%29查找最后一个字符,该字符与sv...

在所有情况下,都通过调用特征:情商...

参数

str

-

string identifying characters to search for

pos

-

position at which the search is to finish

count

-

length of character string identifying characters to search for

s

-

pointer to a character string identifying characters to search for

ch

-

character to search for

sv

-

std::basic_string_view identifying the characters to search for

返回值

已发现字符的位置或npos如果找不到这样的角色。

例外

1-4) (none)

(until C++11)

1,4) noexcept specification: noexcept 2,3) (none)

(since C++11)(until C++14)

1) noexcept specification: noexcept 2,3,4) (none)

(since C++14)

5) noexcept specification: noexcept

(since C++17)

二次

代码语言:javascript
复制
#include<string>
#include<iostream>
int main()
{
    const std::string path="/root/config";
    auto const pos=path.find_last_of('/');
    const auto leaf=path.substr(pos+1);
 
    std::cout << leaf << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
config

二次

另见

find

find characters in the string (public member function)

rfind

find the last occurrence of a substring (public member function)

find_first_of

find first occurrence of characters (public member function)

find_first_not_of

find first absence of characters (public member function)

find_last_not_of

find last absence of characters (public member function)

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

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

扫码关注腾讯云开发者

领取腾讯云代金券