C++ String 库 - find_last_of
描述
它在字符串中搜索与其参数中指定的任何字符匹配的最后一个字符。
声明
以下是 std::string::find_last_of 的声明。
size_t find_last_of (const string& str, size_t pos = npos) const;
C++11
size_t find_last_of (const string& str, size_t pos = npos) const noexcept;
C++14
size_t find_last_of (const string& str, size_t pos = npos) const noexcept;
参数
str − 它是一个字符串对象。
len − 它用于复制字符。
pos − 要复制的第一个字符的位置。
返回值
none
异常
如果抛出异常,则字符串没有变化。
示例
在下面的 std::string::find_last_of 示例中。
#include <iostream>
#include <string>
#include <cstddef>
void SplitFilename (const std::string& str) {
std::cout << "Splitting: " << str << '\n';
std::size_t found = str.find_last_of("/\\");
std::cout << " path: " << str.substr(0,found) << '\n';
std::cout << " file: " << str.substr(found+1) << '\n';
}
int main () {
std::string str1 ("/usr/bin/man");
std::string str2 ("c:\\windows\\winhelp.exe");
SplitFilename (str1);
SplitFilename (str2);
return 0;
}