12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
ADADADADAD
编程知识 时间:2024-12-05 09:58:20
作者:文/会员上传
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
在C++中,rfind函数用于在字符串中查找指定子字符串最后一次出现的位置。它的语法如下:size_t rfind (const string& str, size_t pos = npos) const;其中,str为要查找的子字符
以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。
在C++中,rfind函数用于在字符串中查找指定子字符串最后一次出现的位置。它的语法如下:
size_t rfind (const string& str, size_t pos = npos) const;
其中,str为要查找的子字符串,pos为从哪个位置开始查找,默认为字符串末尾。
该函数返回子字符串在原字符串中最后一次出现的位置的索引,如果未找到则返回string::npos
。
示例:
#include <iostream>#include <string>int main() {std::string str = "hello world";size_t pos = str.rfind("world");if (pos != std::string::npos) {std::cout << "Substring found at position: " << pos << std::endl;} else {std::cout << "Substring not found" << std::endl;}return 0;}
在上面的例子中,rfind函数会查找字符串"world"在"hello world"中最后一次出现的位置,输出为"Substring found at position: 6"。
11-20
11-19
11-20
11-20
11-20
11-19
11-20
11-20
11-19
11-20
11-19
11-19
11-19
11-19
11-19
11-19