C++教程
C++控制语句
C++函数
C++数组
C++指针
C++对象
C++继承
C++多态
C++抽象
C++常用
C++ STL教程
C++迭代器
C++程序

C++ String find_first_not_of()

C++ String find_first_not_of()

此函数用于在字符串中搜索与该字符串中指定的任何字符都不匹配的第一个字符。

语法

请考虑两个字符串str1和str2、语法为:
str1.find_first_not_of(str2);

参数

str: str是用于搜索的字符串。
pos: 它定义了开始搜索的位置。
n: 标识要搜索的字符的字符数。
ch : 定义要搜索的字符

返回值

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

示例1

让我们看一下简单的示例。
#include<iostream>
using namespace std;
int main()
{
string str = "Hello";
cout<< "String contains :" << str <<'\n';
            cout<< str.find_first_not_of("Hllo");
           }   
输出:
String contains : Hello
1

示例2

让我们看一下指定开始搜索位置的简单示例。
#include<iostream>
using namespace std;
int main()
{
string str = "Welcome to the lidihuo";
cout<< "String contains :" << str <<'\n';
cout<< str.find_first_not_of("COME",3);
return 0;
 }
输出:
String contains : Welcome to the lidihuo
3

昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4