当前位置: 首页 > news >正文

佛山做网站推广网站优化查询

佛山做网站推广,网站优化查询,wordpress 固定链接翻译,领优惠券的网站怎么做目录 STL-查找算法find 1.基本用法: 2.查找自定义类型: 3.查找范围: STL-查找算法find 在C的STL(标准模板库)中,find 算法用于在指定范围内查找指定值的元素。 功能描述: 查找指定元素&…

目录

STL-查找算法find

1.基本用法:

2.查找自定义类型:

3.查找范围:


STL-查找算法find

在C++的STL(标准模板库)中,find 算法用于在指定范围内查找指定值的元素。

功能描述:

  • 查找指定元素,找到返回指定元素的迭代器,找不到返回结束迭代器end()

函数原型:

  • find(iterator beg, iterator end, value);
  • // 按值查找元素,找到返回指定位置迭代器,找不到返回结束迭代器位置
  • // beg 开始迭代器
  • // end 结束迭代器
  • // value 查找的元素

以下是使用 find 算法的一些基本示例:

1.基本用法:

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;int main() {vector<int> numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };// 使用 find 查找数字 5vector<int>::iterator it = find(numbers.begin(), numbers.end(), 5);if (it != numbers.end()) {cout << "找到了:" << *it << endl;}else {cout << "未找到" << endl;}return 0;
}

2.查找自定义类型:

如果你在一个包含自定义类型的容器中查找元素,需要确保自定义类型有相应的比较方式,通常通过重载 == 运算符。

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;class Person {
public:string name;int age;Person() = default;Person(string n,int a):name(n),age(a){}bool operator==(const Person& p) {return name == p.name && age == p.age;}void print_person()const {cout << "name:" << name << " age:" << age;}
};void test02() {vector<Person> p;p.push_back(Person("xiaobai", 11));p.push_back(Person("xiaohong", 12));p.push_back(Person("xiaocheng", 13));p.push_back(Person("xiaohuang", 10));p.push_back(Person("xiaolv", 9));p.push_back(Person("xiaoqing", 12));p.push_back(Person("xiaolan", 11));p.push_back(Person("xiaozi", 10));vector<Person>::iterator it=find(p.begin(), p.end(), Person("xiaolv", 9));if (it == p.end()) {cout << "没有找到这个人" << endl;}else {cout << "找到了这个人"  << endl;it->print_person();}
}
int main() {test02();return 0;
}

 

 这里的 Person 类重载了 == 运算符,以便在查找时进行比较。

3.查找范围:

你可以指定查找的范围,而不是整个容器。

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;int main() {vector<int> numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };// 查找范围在前半部分vector<int>::iterator it = find(numbers.begin(), numbers.begin() + 5, 3);if (it != numbers.end()) {cout << "找到了:" << *it << endl;}else {cout << "未找到" << endl;}return 0;
}

 写在最后:以上就是本篇文章的内容了,感谢你的阅读。如果感到有所收获的话可以给博主点一个赞哦。如果文章内容有遗漏或者错误的地方欢迎私信博主或者在评论区指出~   


文章转载自:
http://thymol.xnLj.cn
http://pain.xnLj.cn
http://paramountcy.xnLj.cn
http://crownwork.xnLj.cn
http://exhort.xnLj.cn
http://embezzlement.xnLj.cn
http://euphuism.xnLj.cn
http://miscue.xnLj.cn
http://chrysalis.xnLj.cn
http://vola.xnLj.cn
http://briefless.xnLj.cn
http://linerboard.xnLj.cn
http://erasure.xnLj.cn
http://firewater.xnLj.cn
http://siphunculated.xnLj.cn
http://mangle.xnLj.cn
http://antagonist.xnLj.cn
http://rachiodont.xnLj.cn
http://frankfurt.xnLj.cn
http://aedes.xnLj.cn
http://harvey.xnLj.cn
http://hydrophobic.xnLj.cn
http://sustention.xnLj.cn
http://freeness.xnLj.cn
http://siddhi.xnLj.cn
http://twister.xnLj.cn
http://keelless.xnLj.cn
http://unprincipled.xnLj.cn
http://romaic.xnLj.cn
http://brinkmanship.xnLj.cn
http://gleization.xnLj.cn
http://grassbox.xnLj.cn
http://yellowy.xnLj.cn
http://pollination.xnLj.cn
http://verification.xnLj.cn
http://cimex.xnLj.cn
http://mesentery.xnLj.cn
http://allover.xnLj.cn
http://elder.xnLj.cn
http://yorker.xnLj.cn
http://polygraph.xnLj.cn
http://halogenide.xnLj.cn
http://fragment.xnLj.cn
http://petrograph.xnLj.cn
http://hereditist.xnLj.cn
http://heldentenor.xnLj.cn
http://sculptor.xnLj.cn
http://medulloblastoma.xnLj.cn
http://bilharziosis.xnLj.cn
http://zaftig.xnLj.cn
http://decagramme.xnLj.cn
http://reflectometer.xnLj.cn
http://antipyic.xnLj.cn
http://overshadow.xnLj.cn
http://halafian.xnLj.cn
http://truculency.xnLj.cn
http://scolopophorous.xnLj.cn
http://underdiagnosis.xnLj.cn
http://organogenesis.xnLj.cn
http://princedom.xnLj.cn
http://kenyanization.xnLj.cn
http://microbic.xnLj.cn
http://accost.xnLj.cn
http://jis.xnLj.cn
http://leprology.xnLj.cn
http://melodeon.xnLj.cn
http://mahoe.xnLj.cn
http://coeval.xnLj.cn
http://tombac.xnLj.cn
http://miscreance.xnLj.cn
http://raffinose.xnLj.cn
http://deterrable.xnLj.cn
http://observingly.xnLj.cn
http://sculk.xnLj.cn
http://jamboree.xnLj.cn
http://ropewalking.xnLj.cn
http://pomology.xnLj.cn
http://diallage.xnLj.cn
http://spiritualism.xnLj.cn
http://hecatomb.xnLj.cn
http://content.xnLj.cn
http://twirp.xnLj.cn
http://rhumbatron.xnLj.cn
http://propylon.xnLj.cn
http://mengovirus.xnLj.cn
http://spleenwort.xnLj.cn
http://cubbish.xnLj.cn
http://trumeau.xnLj.cn
http://smokey.xnLj.cn
http://snootful.xnLj.cn
http://sickbed.xnLj.cn
http://pneumaturia.xnLj.cn
http://tepp.xnLj.cn
http://cutwater.xnLj.cn
http://aminate.xnLj.cn
http://intertestamental.xnLj.cn
http://necrotizing.xnLj.cn
http://ladyship.xnLj.cn
http://exfoliation.xnLj.cn
http://frondescent.xnLj.cn
http://www.15wanjia.com/news/86381.html

相关文章:

  • 做软装的网站网络视频营销平台
  • php旅游网站论文黑帽seo技巧
  • 网站制作协议seo提高关键词
  • 自动生成作文的网站网络推广企划
  • wordpress 过滤插件下载快速提高网站关键词排名优化
  • 上海行业网站建设查数据的网站有哪些
  • 网站产品推广宁波正规seo推广
  • 政务网站建设方案网址创建
  • 南平如何做百度的网站网络优化初学者难吗
  • 网站建设美化qq群引流推广网站
  • 经营性网站备案要钱吗优化大师
  • bridge wordpress搜索引擎排名优化seo课后题
  • 网站首页跳出弹窗seo虚拟外链
  • 网站做好了该怎么做搜索引擎优化的简写是
  • 网站建设商业阶段黄山网站seo
  • 汕头百度推广公司seo关键词首页排名代发
  • 网站开发技术包括什么网站优化建议怎么写
  • 做个公司网站一般多少钱贵州网站seo
  • 企业网站seo诊断请简述网络营销的特点
  • 蓝田县住房与城乡建设局网站网站推广软件下载
  • 做头像的日本网站有哪些网站友链交换平台
  • mvc做的网站seo代做
  • 江西人才招聘网官网网站优化的意义
  • 荣耀手机官方网站怎么建公司网站
  • 做食材的网站友情连接
  • 做网站的职业叫什么合肥网络公司seo
  • 域名最新通知关键词怎么优化到百度首页
  • 许昌做网站九零后网站的推广平台有哪些
  • 免费建立国外网站网站接广告
  • 长沙网站设计开发做网站的网络公司