博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c++find函数用法
阅读量:4286 次
发布时间:2019-05-27

本文共 1689 字,大约阅读时间需要 5 分钟。

c++find函数用法

头文件

#include 

函数实现

复制代码

template
InputIterator find (InputIterator first, InputIterator last, const T& val){ while (first!=last) { if (*first==val) return first; ++first; } return last;}

复制代码

例1(vector)

复制代码

#include 
#include
#include
using namespace std;int main(){ vector
m; m.push_back("hello"); m.push_back("hello2"); m.push_back("hello3"); if (find(m.begin(), m.end(), "hello") == m.end()) cout << "no" << endl; else cout << "yes" << endl;}

复制代码

例2(set)

复制代码

#include 
#include
#include
#include
using namespace std;int main(){ set
m; m.insert("hello"); m.insert("hello2"); m.insert("hello3"); if (find(m.begin(), m.end(), "hello") == m.end()) cout << "no" << endl; else cout << "yes" << endl;}

复制代码

注1:set自身有个find函数,举例如下:

复制代码

#include 
#include
#include
#include
using namespace std;int main(){ set
m; m.insert("hello"); m.insert("hello2"); m.insert("hello3"); if (find(m.begin(), m.end(), "hello") == m.end()) cout << "no" << endl; else cout << "yes" << endl;}

复制代码

注2:string自身有个find函数,举例如下:

复制代码

#include 
#include
#include
using namespace std;int main(){ string s = "helllo"; if (s.find("e") == string::npos) //yes cout << "no" << endl; else cout << "yes" << endl; if (s.find("z") == string::npos) //no cout << "no" << endl; else cout << "yes" << endl;}

转载地址:http://lpxgi.baihongyu.com/

你可能感兴趣的文章
cordova-plugin-splashscreen设置启动页面和图标
查看>>
cordova-plugin-camera相机插件使用
查看>>
cordova-plugin-media音频播放和录制
查看>>
Visual Studio 2017使用Emmet风格编写Html--ZenCoding
查看>>
Visual Studio Code v1.21发布
查看>>
C# Newtonsoft.Json JObject移除属性,在序列化时忽略
查看>>
Git移除版本控制操作
查看>>
Http缓存机制(转)
查看>>
C# 本地时间格式,UTC时间格式,GMT时间格式处理
查看>>
Windows系统搭建GitServer--Bonobo Git Server
查看>>
Bootstrap3 datetimepicker控件之smalot的使用
查看>>
小程序Canvas隐藏问题处理
查看>>
小程序scroll-view组件使用简介(转)
查看>>
Visual Studio Code设置中文包/配置中文语言
查看>>
Git重置登录密码问题,Git-remote Incorrect username or password ( access token )
查看>>
C#时间点字符串转换为日期,当天时间点判断
查看>>
Visual Studio Code v1.28.2发布
查看>>
js计算时间差示例
查看>>
VSCode中Vue插件使用整理
查看>>
谷歌浏览器如何隐藏控制台的警告内容打印console.warn()
查看>>