c++find函数用法
头文件
#include <algorithm>
函数实现
template<class InputIterator, class T>
InputIterator find (InputIterator first, InputIterator last, const T& val)
{
while (first!=last)
{
if (*first==val) return first;
++first;
}
return last;
}
例1(vector)
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std; int main()
{
vector<string> 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 <iostream>
#include <algorithm>
#include <string>
#include <set>
using namespace std; int main()
{
set<string> 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 <iostream>
#include <algorithm>
#include <string>
#include <set>
using namespace std; int main()
{
set<string> 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 <iostream>
#include <algorithm>
#include <string>
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;
}
c++find函数用法的更多相关文章
- Oracle 中 decode 函数用法
Oracle 中 decode 函数用法 含义解释:decode(条件,值1,返回值1,值2,返回值2,...值n,返回值n,缺省值) 该函数的含义如下:IF 条件=值1 THEN RETURN(翻译 ...
- memcpy函数用法
memcpy函数用法 .分类: VC++ VC++ mfc matlab 2011-12-01 19:17 14538人阅读 评论(0) 收藏 举报 null 原型:extern void *memc ...
- Python回调函数用法实例详解
本文实例讲述了Python回调函数用法.分享给大家供大家参考.具体分析如下: 一.百度百科上对回调函数的解释: 回调函数就是一个通过函数指针调用的函数.如果你把函数的指针(地址)作为参数传递给另一个函 ...
- php中opendir函数用法实例
这篇文章主要介绍了php中opendir函数用法,以实例形式详细讲述了opendir函数打开目录的用法及相关的注意事项,具有一定的参考借鉴价值,需要的朋友可以参考下 本文实例分析了php中opendi ...
- assert()函数用法总结
assert()函数用法总结 assert宏的原型定义在<assert.h>中,其作用是如果它的条件返回错误,则终止程序执行,原型定义: #include <assert.h> ...
- C语言中qsort函数用法
C语言中qsort函数用法-示例分析 本文实例汇总介绍了C语言中qsort函数用法,包括针对各种数据类型参数的排序,非常具有实用价值非常具有实用价值. 分享给大家供大家参考.C语言中的qsort ...
- OVER(PARTITION BY)函数用法
OVER(PARTITION BY)函数介绍 开窗函数 Oracle从8.1.6开始提供分析函数,分析函数用于计算基于组的某种聚合值,它和聚合函数的不同之处是:对于每个组返 ...
- qsort函数用法【转】
qsort函数用法 qsort 功 能: 使用快速排序例程进行排序 用 法: void qsort(void *base, int nelem, int width, int (*fcmp)(con ...
- Perl Sort函数用法总结和使用实例
一) sort函数用法 sort LISTsort BLOCK LISTsort SUBNAME LIST sort的用法有如上3种形式.它对LIST进行排序,并返回排序后的列表.假如忽略了SUBNA ...
- 关于 pgsql 数据库json几个函数用法的效率测试
关于 pgsql 数据库json几个函数用法的效率测试 关于pgsql 几个操作符的效率测试比较1. json::->> 和 ->> 测试方法:单次运行100次,运行10个单次 ...
随机推荐
- centos 7 的几点改动
1.运行级别 旧:/etc/inittab 新:/etc/ststemd/system 例:ln -sf /lib/systemd/system/multi-user.target /etc/sys ...
- UISearchBar和 UISearchDisplayController的使用
感觉好多文章不是很全面,所以本文收集整合了网上的几篇文章,感觉有互相补充的效果. 如果想下载源码来看:http://code4app.com/search/searchbar .本源码与本文无关 1. ...
- MSN
msn (微软软件) 编辑 MSN,全称Microsoft Service Network,是微软公司(Microsoft)旗下的门户网站. MSN(门户网站)提供包括必应搜索.文娱.健康.理财.汽车 ...
- PHP雪花背景验证码
ValidateCode.class.php 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 ...
- Ubuntu 下忘记mysql 密码
在Ubuntu下忘记密码.可按以下步骤重设:1.停止mysql服务: #/etc/init.d/mysql stop;2,安全模式启动mysql,略过密码验证: # sudo mysqld_safe ...
- [整理]SSRS error:rsReportNotReady
直接访问http://XXX/ReportServer/Pages/ReportViewer.aspx?reportpath&rs%3aCommand=Render执行查询是没有问题的. 但是 ...
- Android Broadcast Receiver 使用入门
Broadcast Receiver 的使用 1.Broadcast Receiver简介 2.Broadcast Receiver接收系统自带的广播 3.自 ...
- iOS文件存储路径规定
Storing Your App’s Data Efficiently https://developer.apple.com/icloud/documentation/data-storage/in ...
- [BZOJ3872][Poi2014]Ant colony
[BZOJ3872][Poi2014]Ant colony 试题描述 There is an entrance to the ant hill in every chamber with only o ...
- django-cms 代码研究(三)插件(plugs in)
插件(plugs in) djangocms支持的插件有: http://docs.django-cms.org/en/latest/basic_reference/plugin_reference. ...