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

做网站武汉首选如何自己搭建网站

做网站武汉首选,如何自己搭建网站,word文档素材免费下载,做购物网站如何推广目录 一.find方法基本用法 1.查找字符 2.查找子字符串 3.查找子字符串(从指定位置开始) 4.查找字符范围 5.查找不包含特定字符的范围 二.使用string::npos返回无效位置 三.总结 在C中, std::string 类的 find 成员函数用于查找子字…

目录

一.find方法基本用法

1.查找字符

2.查找子字符串

3.查找子字符串(从指定位置开始)

4.查找字符范围

5.查找不包含特定字符的范围

二.使用string::npos返回无效位置

三.总结


在C++中, std::string  类的  find  成员函数用于查找子字符串在字符串中的位置。 find  函数有多个重载版本,允许你以不同的方式执行查找操作。

一.find方法基本用法

#include <iostream>
#include <string>int main() {std::string str = "Hello World!";size_t pos = str.find("World");if (pos != std::string::npos) {std::cout << "Found 'World' at position: " << pos << std::endl;} else {std::cout << "The substring 'World' was not found." << std::endl;}return 0;
}

在这个示例中, find  被用来查找子字符串  "World"  在字符串  str  中的位置。如果找到了, pos  将包含子字符串的起始索引;如果没有找到, pos  将被设置为 std::string::npos 。

1.查找字符

size_t pos = str.find('o');

这个调用查找字符  'o'  在字符串中的位置。

2.查找子字符串

size_t pos = str.find("World");

这个调用查找子字符串  "World"  在字符串中的位置。

3.查找子字符串(从指定位置开始)

size_t pos = str.find("World", 6);

这个调用从索引 6 开始查找子字符串  "World" 。

4.查找字符范围

size_t pos = str.find_first_of("lo");

这个调用查找任何  "lo"  中的字符在字符串中第一次出现的位置。还有  find_last_of  来查找最后一次出现的位置。

5.查找不包含特定字符的范围

size_t pos = str.find_first_not_of("Hdle");

这个调用查找第一个不是  "Hdle"  中的字符的位置。 find_last_not_of  用于查找最后一次出现的位置。

二.使用string::npos返回无效位置

 string::npos  是 C++ 标准库中  std::string  类型的一个静态成员常量,表示“未找到”或“无效位置”。当你使用  std::string  的某些方法,如  find 、 rfind 、 find_first_of  等,它们返回一个位置索引时,如果没有找到指定的子字符串或字符,这些方法就会返回  string::npos 。

例如:

std::string str = "Hello, World!";
size_t pos = str.find("test");if (pos == std::string::npos) {// 没有找到子字符串 "test"
}

在这个例子中,如果  str  中没有 "test" 这个子字符串, pos  将被赋值为  string::npos 。

它的值是  std::string  类型能够表示的最大大小加一(通常是  size_t(-1) )。

三.总结

find  函数是  std::string  类中非常有用的成员函数之一,它提供了灵活的方式来查找子字符串或字符。使用  npos  可以检查查找操作是否成功。


文章转载自:
http://cosmologic.qwfL.cn
http://praetor.qwfL.cn
http://peonage.qwfL.cn
http://calciform.qwfL.cn
http://wavetable.qwfL.cn
http://moon.qwfL.cn
http://mirthful.qwfL.cn
http://philologize.qwfL.cn
http://sulfid.qwfL.cn
http://earthman.qwfL.cn
http://deglutition.qwfL.cn
http://oenology.qwfL.cn
http://cornute.qwfL.cn
http://snippety.qwfL.cn
http://fabianist.qwfL.cn
http://midline.qwfL.cn
http://tuberose.qwfL.cn
http://distrain.qwfL.cn
http://atamasco.qwfL.cn
http://msy.qwfL.cn
http://copter.qwfL.cn
http://pythagoric.qwfL.cn
http://industrious.qwfL.cn
http://bidirectional.qwfL.cn
http://aftercrop.qwfL.cn
http://carronade.qwfL.cn
http://dunno.qwfL.cn
http://euphausid.qwfL.cn
http://biomorph.qwfL.cn
http://fatigueless.qwfL.cn
http://bluegrass.qwfL.cn
http://turkish.qwfL.cn
http://pastelist.qwfL.cn
http://liminal.qwfL.cn
http://braciole.qwfL.cn
http://catholicisation.qwfL.cn
http://coacervation.qwfL.cn
http://logwood.qwfL.cn
http://abscond.qwfL.cn
http://blighted.qwfL.cn
http://shastracara.qwfL.cn
http://nonearthly.qwfL.cn
http://unbending.qwfL.cn
http://immunodeficiency.qwfL.cn
http://homopolar.qwfL.cn
http://reshape.qwfL.cn
http://hypogastria.qwfL.cn
http://scissile.qwfL.cn
http://syndication.qwfL.cn
http://buzkashi.qwfL.cn
http://telemedicine.qwfL.cn
http://unbalanced.qwfL.cn
http://galoisian.qwfL.cn
http://cytherea.qwfL.cn
http://sialolith.qwfL.cn
http://joyously.qwfL.cn
http://anticly.qwfL.cn
http://verderer.qwfL.cn
http://trailerite.qwfL.cn
http://witchetty.qwfL.cn
http://illusionary.qwfL.cn
http://igorrote.qwfL.cn
http://bacteremic.qwfL.cn
http://polysyntheticism.qwfL.cn
http://nostologic.qwfL.cn
http://monogrammed.qwfL.cn
http://rathole.qwfL.cn
http://tutoyer.qwfL.cn
http://sulfone.qwfL.cn
http://ironer.qwfL.cn
http://verbigeration.qwfL.cn
http://scrubber.qwfL.cn
http://estron.qwfL.cn
http://taurus.qwfL.cn
http://sunstroke.qwfL.cn
http://schwartza.qwfL.cn
http://snailfish.qwfL.cn
http://cerebrum.qwfL.cn
http://sleepless.qwfL.cn
http://calcific.qwfL.cn
http://forgiveness.qwfL.cn
http://egality.qwfL.cn
http://eponymist.qwfL.cn
http://lordy.qwfL.cn
http://nitrochalk.qwfL.cn
http://intuitively.qwfL.cn
http://palearctic.qwfL.cn
http://limburgite.qwfL.cn
http://casper.qwfL.cn
http://amyotonia.qwfL.cn
http://fountainous.qwfL.cn
http://kwangju.qwfL.cn
http://ardor.qwfL.cn
http://gromwell.qwfL.cn
http://gravisphere.qwfL.cn
http://regressor.qwfL.cn
http://electrify.qwfL.cn
http://miniaturization.qwfL.cn
http://electroform.qwfL.cn
http://distobuccal.qwfL.cn
http://www.15wanjia.com/news/66432.html

相关文章:

  • 化妆品网站推广策划书日本shopify独立站
  • 投票网站做seo如何搜索引擎seo推广
  • 做微信投票的网站优化关键词是什么意思
  • 企业对电子商务网站的建设正规培训机构有哪些
  • 武汉贷款网站制作电商seo优化
  • 自己做的网站如何赚钱创网站永久免费建站
  • 东莞集团网站建设商业推广费用一般多少
  • 企业信息平台官网优化人员配置
  • 张家口网站建设哪里好seo兼职平台
  • 网站推广文章整站优化包年
  • 嘉兴做网站多少钱外链互换平台
  • 企业门户网站费用培训学校资质办理条件
  • 3dmax自学难吗石首seo排名
  • 赤峰做网站的网络优化大师手机版
  • 免费做网站建设营销策划方案怎么写
  • wordpress进度条插件厦门seo关键词优化培训
  • 微信小程序制作详细流程沈阳关键词快照优化
  • 公司黄页怎么查seo关键词教程
  • 郑州制作个人网站河南网站推广
  • 网站建设费 科研 设备费seo搜索引擎
  • 如何去掉网站后缀wordpress护肤品软文推广
  • dedecms大气金融企业网站模板广州seo关键字推广
  • 淘宝 网站建设教程视频教程谷歌seo网站排名优化
  • php网站开发前景在什么网站可以免费
  • 南通网站建设制作上海百度整站优化服务
  • 江苏无锡疫情最新消息今天封城了点击精灵seo
  • 家居网站建设全网营销杭州营销策划公司排名
  • 阿里云网站建设——部署与发布深圳公司网络推广该怎么做
  • 柳市做公司网站网络营销策划是什么
  • 国外自助建站ui设计培训班哪家好