进程 中的 int find_last_of(string& s

首页 / C++入门教程 / 进程 中的 int find_last_of(string& s

此函数在字符串中搜索与字符串中指定的任何字符匹配的最后一个字符。

find_last_of - 语法

str1.find_last_of(str2);

find_last_of - 参数

str  -  str是用于搜索的字符串。

pos -  它定义开始搜索的位置。

n      -  标识要搜索的字符的字符数。

ch    -  它定义了要搜索的字符

find_last_of - 返回值

它返回不匹配的第一个字符的位置。

find_last_of - 例子1

让我们看一个简单的例子。

#include<iostream>
using namespace std;
int main()
{
string str = "I love India";
cout<< "String contains :" << str <<'\n';
cout<< str.find_last_of("love");
return 0;
} 

输出:

String contains : I love India
    5

find_last_of - 例子2

让我们看一个简单的示例,其中指定了开始搜索的位置。

无涯教程网

#include<iostream>
using namespace std;
int main()
{
        string str = "C++ Tutorial";
       cout<< "String contains :" << str <<'\n';
      cout<< str.find_last_of("Tutorial",3);
       return 0;
}   

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

程序员进阶攻略 -〔胡峰〕

Flutter核心技术与实战 -〔陈航〕

性能测试实战30讲 -〔高楼〕

Kafka核心源码解读 -〔胡夕〕

软件设计之美 -〔郑晔〕

如何落地业务建模 -〔徐昊〕

零基础实战机器学习 -〔黄佳〕

反爬虫兵法演绎20讲 -〔DS Hunter〕

徐昊 · TDD项目实战70讲 -〔徐昊〕

好记忆不如烂笔头。留下您的足迹吧 :)