成都设计公司视频制作亚马逊关键词优化软件

news/2025/10/6 23:04:41/文章来源:
成都设计公司视频制作,亚马逊关键词优化软件,常州做的网站的公司网站,资讯网站怎么做【C】使用 list 与 string 实现基础字符串操作 文章目录 一、字符串的基础操作1.1 - startsWith1.2 - endsWith1.3 - trim1.4 - indexOf1.5 - replaceAll 二、list 基础操作2.1 - 遍历2.1.1 - 使用迭代器访问2.1.2 - 使用基于范围的 for 循环遍历2.1.3 - 使用标准算法库遍历 2.… 【C】使用 list 与 string 实现基础字符串操作 文章目录 一、字符串的基础操作1.1 - startsWith1.2 - endsWith1.3 - trim1.4 - indexOf1.5 - replaceAll 二、list 基础操作2.1 - 遍历2.1.1 - 使用迭代器访问2.1.2 - 使用基于范围的 for 循环遍历2.1.3 - 使用标准算法库遍历 2.2 - 访问元素2.3 - 删除元素 三、list\string\3.1 - 移除所有空字符串元素3.2 - 遍历字符串并应用 trim3.3 - 移除连续的空白行 一、字符串的基础操作 1.1 - startsWith bool startsWith(const std::string fullString, const std::string starting) {if (fullString.length() starting.length()) {return (0 fullString.compare(0, starting.length(), starting));} else {return false;} }1.2 - endsWith bool endsWith(const std::string fullString, const std::string ending) {if (fullString.length() ending.length()){return (0 fullString.compare(fullString.length() - ending.length(), ending.length(), ending));}else{return false;} }1.3 - trim 用于移除字符串前后两端的空白符 // Function to trim whitespace from the beginning and end of a string std::string trim(const std::string str) {size_t first str.find_first_not_of( \t\n\r\f\v);// No non-whitespace charactersif (first std::string::npos){ // 如果从头开始非空白符找不到说明所有的字符都是空白符因此全部去掉return ; }size_t last str.find_last_not_of( \t\n\r\f\v);// 即便 last 为 string::npos substr 也会做处理。return str.substr(first, (last - first 1)); }或者 #include algorithm #include cctype// 去除字符串左侧空白 static inline void ltrim(std::string s) {s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) {return !std::isspace(ch);})); }// 去除字符串右侧空白 static inline void rtrim(std::string s) {s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) {return !std::isspace(ch);}).base(), s.end()); }// 去除字符串两侧空白 static inline void trim(std::string s) {ltrim(s);rtrim(s); }1.4 - indexOf 用于获取第一个子串的位置索引如果找不到则返回 -1。 // Function to find the index of the first occurrence of a substring int indexOf(const std::string str, const std::string substr) {size_t pos str.find(substr);return (pos ! std::string::npos) ? static_castint(pos) : -1; }1.5 - replaceAll // 替换字符串中所有匹配的子字符串 void replaceAll(std::string source, const std::string from, const std::string to) {// 如果字符串为空则返回。if (from.empty()) { return; }size_t startPos 0;while ((startPos source.find(from, startPos)) ! std::string::npos) {source.replace(startPos, from.length(), to);startPos to.length(); // 在替换后移动过去新增的部分} }二、list 基础操作 2.1 - 遍历 2.1.1 - 使用迭代器访问 #include iostream #include list std::listint myList {1, 2, 3, 4, 5};// 使用迭代器遍历 std::list for (auto it myList.begin(); it ! myList.end(); it) {std::cout *it ; } std::cout std::endl;2.1.2 - 使用基于范围的 for 循环遍历 #include iostream #include list // 使用范围基 for 循环遍历 std::list for (int elem : myList) {std::cout elem ; } std::cout std::endl;2.1.3 - 使用标准算法库遍历 #include iostream #include list #include algorithm // for std::for_each std::listint myList {1, 2, 3, 4, 5};// 使用 std::for_each 遍历 std::list std::for_each(myList.begin(), myList.end(), [](int elem) {std::cout elem ; }); std::cout std::endl;2.2 - 访问元素 访问第 N 个元素 #include iostream #include liststd::listint myList {10, 20, 30, 40, 50}; int N 3; // 以 0 为起始索引访问第 4 个元素 auto it myList.begin(); std::advance(it, N); // 使用 std::advance 前进到第 N 个元素if (it ! myList.end()) {std::cout The element at index N is *it std::endl; } else {std::cout Index out of range. std::endl; }2.3 - 删除元素 删除前 N 个元素 std::listint myList {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};int N 3; // 指定要删除的元素数量 if (N myList.size()) {// 获取开始到第 N 个元素的迭代器auto it myList.begin();std::advance(it, N); // 移动迭代器到第 N 个位置// 从开始到第 N 个元素进行删除myList.erase(myList.begin(), it); }// 打印剩余的元素 for (int elem : myList) {std::cout elem ; } std::cout std::endl;三、liststring 3.1 - 移除所有空字符串元素 #include iostream #include list #include string// 创建并初始化一个 std::liststd::string std::liststd::string strings {Hello, , World, , C17, }; // 输出原始列表 std::cout Original list: std::endl; for (const auto str : strings) {std::cout str std::endl; } // 移除所有空字符串 strings.remove_if([](const std::string s) { return s.empty(); }); // 输出修改后的列表 std::cout \nList after removing empty strings: std::endl; for (const auto str : strings) {std::cout str std::endl; }3.2 - 遍历字符串并应用 trim std::liststd::string myStrings { hello , world! , example };// 遍历列表并应用 trim 函数 for (std::string str : myStrings) {trim(str); } // 打印修剪后的字符串列表 for (const auto str : myStrings) {std::cout str std::endl; }3.3 - 移除连续的空白行 将多个连续的空白行替换为一个空白行 #include iostream #include list #include string #include iteratorvoid compressEmptyLines(std::liststd::string lines) {bool lastWasEmpty false;for (auto it lines.begin(); it ! lines.end(); ) {// 检查当前行是否为空白或只包含空格bool isEmpty it-find_first_not_of( \t\n\v\f\r) std::string::npos;if (isEmpty) {if (lastWasEmpty) {// 如果当前行是空的并且上一行也是空的删除当前行it lines.erase(it);} else {// 如果当前行是空的但上一行不是保留这行并标记lastWasEmpty true;it;}} else {// 如果当前行不是空的继续前进lastWasEmpty false;it;}} }int main() {std::liststd::string lines {Hello, , ,World,,,!, ,End};compressEmptyLines(lines);// 输出处理后的列表for (const auto line : lines) {std::cout line std::endl;}return 0; }

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/929794.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

1-50 题解

1-10 1. A + B Problem #include <iostream> using namespace std;int main(){int a,b; cin>>a>>b;cout<<a+b<<endl;return 0; }2. Two Rectangles #include <iostream> using n…

基于AXI模块的视频流传输(ps控制篇)

在生成VDMA,GPIO,IIC后,会生成对于的bsp板级包。这里我不打算进行深入学习(不会尝试自己去写这份ps代码),要求能较为深入理解ps工作的原理即可,依旧不去细看HDMI模块相关。首先导入了几个库,然后定义了几个宏,…

lora的各种变体

lora的各种变体:lora+:对A(靠近输入端)和B(靠近输出端)设置不同的学习率以加速收敛,对B的学习率通常是A的4到16倍,这是因为近输出层的梯度更加稳定,近输入层的梯度相对不稳定,如果设置的学习率过大,容易梯度…

GO+RabbitMQ+Gin+Gorm+docker 部署 demo - 实践

GO+RabbitMQ+Gin+Gorm+docker 部署 demo - 实践pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", &…

k8s pod启动失败困难排查

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

Python测试

今日内容pycharm安装 git 版本控制 -- 协同开发 码云 -- 远程仓库 思维导图 个人博客 -- 技术人员昨日回顾typora 安装 使用标题 有序序号 无序序号 加粗 斜体 删除线 插入图片 插入表格 代码块、python的简介python2和…

免费文字转语音 AI 工具 All In One

免费文字转语音 AI 工具 All In One free TTS to Audio AI Tools TTSMaker 免费文字转语音免费文字转语音 AI 工具 All In Onefree TTS to Audio AI ToolsTTSMaker 免费文字转语音 每周限制 20000 个字符(部分声音可支…

Kubernetes Deployment:部署与管理应用指南

1. ReplicaSet(RS) 2. Deployment 3. Deployment资源配置 总结‍在上一章节中,介绍了pod,以及介绍了如何使用命令行来创建一个pod。那么问题来了,一般来说,我们部署微服务不可能只部署一个噻,肯定是部署多个,但…

wordpres做影视网站公关策划书模板范文

宏定义 不带参数 宏定义又称为宏代换、宏替换&#xff0c;简称“宏”。 格式&#xff1a; #define 标识符 字符串其中的标识符就是所谓的符号常量&#xff0c;也称为“宏名”。 预处理&#xff08;预编译&#xff09;工作也叫做宏展开&#xff1a;将宏名替换为字符串。 掌…

实用指南:Android高级开发第三篇 - JNI异常处理与线程安全编程

实用指南:Android高级开发第三篇 - JNI异常处理与线程安全编程pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Co…

商城网站设计公司系统优化包括哪些

作者推荐 视频算法专题 本文涉及知识点 哈希映射 哈希集合 LeetCode 381. O(1) 时间插入、删除和获取随机元素 - 允许重复 RandomizedCollection 是一种包含数字集合(可能是重复的)的数据结构。它应该支持插入和删除特定元素&#xff0c;以及删除随机元素。 实现 Randomiz…

判断网站开发语言wordpress 访问速度

来源&#xff1a;德先生作者&#xff1a;朱圆恒&#xff0c;唐振韬&#xff0c;李伟凡&#xff0c;赵冬斌北京时间2019年1月25日2时&#xff0c;DeepMind在伦敦向世界展示了他们的最新成果——星际争霸2人工智能AlphaStar[1] 。图1. DeepMind AlphaStar挑战星际人类职业玩家直播…

分布式CAP理论 - 指南

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

【闲话】2025.9.24 记梦

破碎,离奇。话说 \(9.25\) 吃了 \(hz\) 校庆期间 \(hs\) 食堂免费饭菜的人第二天都被抓去做黑工,我和 @wkh2008 因为当时润去不知道干什么了所以没有被抓走,第二天回到班里发现毫无人,然后被学校里巡游的中介带走。…

北京撒网站设计git网站开发

文章目录 目录1. 程序的翻译环境和执行环境2. 详解编译链接2.1 翻译环境2.2 编译本身也分为几个阶段2.3 运行环境 3. 预处理详解3.1 预定义符号3.2 #define3.2.1 #define 定义标识符3.2.2 #define 定义宏3.2.3 #define 替换规则3.2.4 #和##3.2.5 带副作用的宏参数3.2.6 宏和函数…

完整教程:Postgresql常规SQL语句操作

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

酷派Cool20/20S/30/40手机安装Play商店-谷歌三件套-GMS方式

酷派Cool20/20S/30/40手机安装Play商店-谷歌三件套-GMS方式pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consol…

拼多多电商网站建设学校网站建设方案设计

使用 services 指令&#xff0c;请先安装 brew tap gapple/services 安装完成后使用 brew services start mysql

关于网络编辑作业做网站栏目新闻的ppt免费网站软件大全

今年有哪些成功的发行版发布呢&#xff1f; 让我重点介绍最好的几个。 这些发行版在 2023 年引起了人们的关注&#xff01; 每年我们都会推出一些令人兴奋的新发行版&#xff0c;它们尝试以不同的方式工作&#xff0c;或者提供一些有意义的东西&#xff0c;而不仅仅是“又一个发…

【sa-token】 sa-token非 web 上下文无法获取 HttpServletRequest - 实践

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …