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

一个网站需要多少网页做网咖的网站

一个网站需要多少网页,做网咖的网站,ping wordpress,杭州模板网站建站在 C 的 std::string 类中,有几个成员函数可以用于在字符串中执行搜索和子字符串提取操作。以下是这些函数的简要说明: find(): 查找子字符串的第一个出现位置。 size_t find(const string& str, size_t pos 0) const; size_t find(const char* s, …

在 C++ 的 std::string 类中,有几个成员函数可以用于在字符串中执行搜索和子字符串提取操作。以下是这些函数的简要说明:

  1. find(): 查找子字符串的第一个出现位置。

    size_t find(const string& str, size_t pos = 0) const;
    size_t find(const char* s, size_t pos = 0) const;
    

    这个函数返回子字符串 str 或 C 字符串 s 第一次出现的位置(索引)。可以指定搜索的起始位置 pos。如果找不到子字符串,返回 string::npos

  2. rfind(): 反向查找子字符串的最后一个出现位置。

    size_t rfind(const string& str, size_t pos = npos) const;
    size_t rfind(const char* s, size_t pos = npos) const;
    

    这个函数返回子字符串 str 或 C 字符串 s 最后一次出现的位置(索引)。可以指定搜索的起始位置 pos,默认情况下从字符串的末尾开始搜索。如果找不到子字符串,返回 string::npos

  3. find_first_of(): 查找给定字符集合中任意字符第一次出现的位置。

    size_t find_first_of(const string& str, size_t pos = 0) const;
    size_t find_first_of(const char* s, size_t pos = 0) const;
    

    这个函数返回在子字符串 str 或 C 字符串 s 中任意字符的第一次出现的位置(索引)。可以指定搜索的起始位置 pos。如果找不到字符,返回 string::npos

  4. find_last_of(): 反向查找给定字符集合中任意字符最后一次出现的位置。

    size_t find_last_of(const string& str, size_t pos = npos) const;
    size_t find_last_of(const char* s, size_t pos = npos) const;
    

    这个函数返回在子字符串 str 或 C 字符串 s 中任意字符的最后一次出现的位置(索引)。可以指定搜索的起始位置 pos,默认情况下从字符串的末尾开始搜索。如果找不到字符,返回 string::npos

  5. substr(): 提取子字符串。

    string substr(size_t pos = 0, size_t len = npos) const;
    

    这个函数返回从位置 pos 开始,长度为 len 的子字符串副本。如果省略 len,则返回从 pos 开始的剩余部分。

具体示例:

#include <iostream>
#include <string>int main() {std::string str = "Hello, World!";// 使用 find() 查找子字符串的第一个出现位置size_t pos = str.find("World");if (pos != std::string::npos) {std::cout << "'World' found at position " << pos << std::endl;} else {std::cout << "'World' not found" << std::endl;}// 使用 rfind() 反向查找子字符串的最后一个出现位置size_t pos_reverse = str.rfind("o");if (pos_reverse != std::string::npos) {std::cout << "'o' found at position " << pos_reverse << std::endl;} else {std::cout << "'o' not found" << std::endl;}// 使用 find_first_of() 查找给定字符集合中任意字符的第一个出现位置size_t pos_first_of = str.find_first_of("eio");if (pos_first_of != std::string::npos) {std::cout << "Any of 'eio' found at position " << pos_first_of << std::endl;} else {std::cout << "Any of 'eio' not found" << std::endl;}// 使用 find_last_of() 反向查找给定字符集合中任意字符的最后一个出现位置size_t pos_last_of = str.find_last_of("rlod");if (pos_last_of != std::string::npos) {std::cout << "Any of 'rlod' found at position " << pos_last_of << std::endl;} else {std::cout << "Any of 'rlod' not found" << std::endl;}// 使用 substr() 提取子字符串std::string substr = str.substr(7, 5);std::cout << "Substring: " << substr << std::endl;return 0;
}

输出结果:

'World' found at position 7
'o' found at position 8
Any of 'eio' found at position 1
Any of 'rlod' found at position 13
Substring: World

以上示例演示了如何使用这些函数在字符串中查找子字符串并提取子字符串的各种操作。

http://www.yayakq.cn/news/694808/

相关文章:

  • 网站前端设计做包装用哪个网站
  • 寿光专业做网站优服优科网站建设公司
  • 沧州国外网站建设python和c++学哪个好
  • 肇庆自助建站模板网站运营内容包含哪些
  • 网站建立时间查询线上平台建设怎么做
  • 网站设计优缺点如何诊断网站seo
  • 优秀个人博客网站酒店网络营销推广案例
  • 牛股大转盘网站建设哈尔滨免费自助建站模板
  • 甘肃省建设厅官方网站张睿这几年做哪些网站致富
  • 网站到期不想续费在线电子商务网站开发
  • 如何做游戏渠道网站网站做细分领域
  • 上海网站建设网站开发可以推广的软件有哪些
  • 中山台州网站建设推广微网站 网页
  • 网站建设怎么引流做cpa没有网站怎么办
  • 登封网站设计免费背景图片素材网
  • 仿win8网站酒店网站建设工作
  • 明星静态网站英文外贸网站设计
  • aspx网站搭建教程网站制作好学吗
  • 福州做网站外包成都网络营销
  • 建站设计做甜品的网站
  • 非主流图片在线制作衡阳seo网络营销方案
  • 成都网站推广排名墙外必去的网站
  • 怎样创建自己的电商平台平台优化是指什么
  • 东莞外贸公司建网站顺平网站建设
  • 网站导航一定要一样吗国外做微课的网站
  • 公司自建网站做网站推广选择什么最好
  • 免费搭建自己的网站房源网
  • 自助建站英文企业主页是什么
  • 网站做淘宝客收入咋样做信公众号首图的网站
  • 网站运营论文w3c验证网站