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

string容器

目录

string函数的构造

string赋值操作

string字符串拼接

string字符串查找和替换

string字符串比较

string字符存取

string插入与删除

string字串


string函数的构造

#include<iostream>
#include<cstring>
using namespace std;
void test01()
{string s1;//默认构造const char* str = "hello world";string s2(str);cout << "s2 = " << s2 << endl;string s3(s2);cout << "s3 = " << s3 << endl;string s4(10, 'a');cout << "s4 = " << s4 << endl;
}
int main()
{test01();system("pause");return 0;
}

string赋值操作

//author:至尊宝
//time:2024.5.5
#include<iostream>
#include<cstring>
using namespace std;
void test01()
{string str1;str1 = "hello world";cout << "str1 = " << str1 << endl;string str2;str2 = str1;cout << "str2 = " << str2 << endl;string str3;str3 = 'a';cout << "str3 = " << str3 << endl;string str4;str4.assign("hello C++");cout << "str4 = " << str4 << endl;string str5;str5.assign("hello C++", 5);cout << "str5 = " << str5 << endl;string str6;str6.assign(str5);cout << "str6 = " << str6 << endl;string str7;str7.assign(10, 'b');cout << "str7 = " << str7 << endl;
}
int main()
{test01();system("pause");return 0;
}

string字符串拼接

//author:至尊宝
//time:2024.5.5
#include<iostream>
#include<cstring>
using namespace std;
void test01()
{string str1 = "我";str1 += "爱玩游戏";cout << "str1 = " << str1 << endl;str1 += ':';cout << "str1 = " << str1 << endl;string str2 = "LOL DNF";str1 += str2;cout << "str1 = " << str1 << endl;string str3 = "I";str3.append(" love ");cout << "str3 = " << str3 << endl;str3.append("game abcde", 4);cout << "str3 = " << str3 << endl;/*str3.append(str2);cout << "str3 = " << str3 << endl;*///截取DNFstr3 += ' ';str3.append(str2, 4, 3);cout << "str3 = " << str3 << endl;
}
int main()
{test01();system("pause");return 0;
}

string字符串查找和替换

//author:至尊宝
//time:2024.5.5
#include<iostream>
#include<cstring>
using namespace std;
void test01()
{string str1 = "abcdefg";int pos = str1.find("deo");if (pos == -1){cout << "未找到字符串" << endl;}else{cout << "找到字符串" << ",pos = " << pos << endl;}//rfindpos = str1.rfind("de");cout << "pos = " << pos << endl;//rfind从右往左查找,find从左往右查找
}
void test02()
{string str1 = "abcdefg";//从一号位置起3个字符替换为1111str1.replace(1, 3, "1111");cout << "str1 = " << str1 << endl;
}
int main()
{test02();system("pause");return 0;
}

string字符串比较

//author:至尊宝
//time:2024.5.5
#include<iostream>
#include<cstring>
using namespace std;
void test01()
{string str1 = "xello";string str2 = "hello";if (str1.compare(str2) == 0){cout << "str1等于str2" << endl;}else if (str1.compare(str2) > 0){cout << "str1大于str2" << endl;}else{cout << "str1小于str2" << endl;}
}int main()
{test01();return 0;
}

string字符存取

//author:至尊宝
//time:2024.5.5
#include<iostream>
#include<cstring>
using namespace std;
void test01()
{string str = "hello";cout << "str = " << str << endl;//单个字符//1.中括号for (int i = 0; i < str.size(); i++){cout << str[i];}cout << endl;//2.atfor (int i = 0; i < str.size(); i++){cout << str.at(i);}cout << endl;//修改单个str[0] = 'x';cout << "str = " << str<<endl;str.at(1) = 'x';cout << "str = " << str << endl;
}int main()
{test01();return 0;
}

string插入与删除

//author:至尊宝
//time:2024.5.5
#include<iostream>
#include<cstring>
using namespace std;
void test01()
{string str = "hello";//插入str.insert(1, "111");cout << "str = " << str << endl;//删除str.erase(1, 3);cout << "str = " << str << endl;
}int main()
{test01();return 0;
}

string字串

//author:至尊宝
//time:2024.5.5
#include<iostream>
#include<cstring>
using namespace std;
void test01()
{string str = "abcdef";string str2 = str.substr(1, 3);cout << str2 << endl;
}
void test02()
{string email = "hello@sina.com";//从邮件地址中获取用户名信息int pos = email.find("@");string name = email.substr(0, pos);cout << name << endl;
}int main()
{test02();return 0;
}

相关文章:

string容器

目录 string函数的构造 string赋值操作 string字符串拼接 string字符串查找和替换 string字符串比较 string字符存取 string插入与删除 string字串 string函数的构造 #include<iostream> #include<cstring> using namespace std; void test01() {string s…...

Ansible-inventory和playbook

文章目录 一、inventory 主机清单1、列表表示2、inventory 中的变量3、变量3.1 主机变量3.2 组变量3.3 组嵌套 二、playbook剧本1、playbook的组成2、编写剧本2.1 剧本制作2.2 准备nginx.conf2.3 运行剧本2.4 查看webservers服务器2.5 补充参数 3、剧本定义、引用变量3.1 剧本制…...

HI3516CV610

一、总体介绍 HI3516CV610是一颗应用在安防市场的IPC SoC&#xff0c;在开放操作系统、新一代视频编解码标准网络安全和隐私保护、人工智能方面引领行业发展&#xff0c;主要面向室内外场景下的枪机、球机、半球机、海螺机、枪球一体机、双目长短焦机等产品形态&#xff0c;打…...

ansible内置主机变量及魔法变量

目录 概述实践代码执行效果 概述 简单实用版本 实践 代码 --- - name: Get IP Addresshosts: allgather_facts: notasks:- name: Get IP Addressansible.builtin.setup:register: host_ip- name: Print IP Addressansible.builtin.debug:msg: "The IP Address of {{ a…...

设计模式一

单例模式&#xff08;Singleton Pattern&#xff09;是一种常用的软件设计模式&#xff0c;旨在确保一个类只有一个实例&#xff0c;并提供一个全局访问点。单例模式常用于控制资源密集型对象的创建&#xff0c;如数据库连接池、线程池等&#xff0c;以避免资源浪费。 单例模式…...

MySQL中JOIN连接的实现算法

目录 嵌套循环算法&#xff08;NLJ&#xff09; 简单嵌套循环&#xff08;SNLJ&#xff09; 索引嵌套循环&#xff08;INLJ&#xff09; 块嵌套循环&#xff08;BNLJ&#xff09; 三种算法比较 哈希连接算法&#xff08;Hash Join&#xff09; 注意事项&#xff1a; 工…...

[力扣题解] 216. 组合总和 III

题目&#xff1a;216. 组合总和 III 思路 回溯法 代码 class Solution { private:vector<vector<int>> result;vector<int> path;public:void function(int k, int n, int startindex, int sum){int i;// 剪枝// 超过了, 不用找了;if(sum > n){return…...

Spring Security Oauth2 JWT 添加额外信息

目录 一、问题描述 二、实现步骤 1、自定义TokenEnhancer 2、配置授权服务器 3、自定义UserDetails的User类 三、参考文档 一、问题描述 Oauth2里默认生成的JWT信息并没有用户信息&#xff0c;在认证授权后一般会返回这一部分信息&#xff0c;我对此进行了改造。 Oauth…...

蜜蜂收卡系统 加油卡充值卡礼品卡自定义回收系统源码 前后端开源uniapp可打包app

本文来自&#xff1a;蜜蜂收卡系统 加油卡充值卡礼品卡自定义回收系统源码 前后端开源uniapp可打包app - 源码1688 卡券绿色循环计划—— 一项旨在构建卡券价值再利用生态的社会责任感项目。在当前数字化消费日益普及的背景下&#xff0c;大量礼品卡、优惠券因各种原因未能有效…...

三星硬盘好还是西数硬盘好?硬盘数据丢失怎么找回

在数字化时代&#xff0c;硬盘作为数据存储的核心组件&#xff0c;其品质与性能直接关系到用户的数据安全与使用体验。在众多硬盘品牌中&#xff0c;三星与西数无疑是两个备受关注的名字。那么&#xff0c;究竟是三星硬盘更胜一筹&#xff0c;还是西数硬盘更受用户青睐&#xf…...

企业微信hook接口协议,ipad协议http,设置是否自动同意

设置是否自动同意 参数名必选类型说明uuid是String每个实例的唯一标识&#xff0c;根据uuid操作具体企业微信 请求示例 {"uuid":"bc4800492083fdec4c1a7e5c94","state":1 //1 是需要验证同意&#xff08;需要手动点击同意&#xff09; 0关闭验证…...

自动化测试的成本高效果差,那么自动化测试的意义在哪呢?

有人问&#xff1a;自动化测试的成本高效果差&#xff0c;那么自动化测试的意义在哪呢&#xff1f; 我觉得这个问题带有很强的误导性&#xff0c;是典型的逻辑陷阱之一。“自动化测试的成本高效果差”是真的吗&#xff1f;当然不是。而且我始终相信&#xff0c;回答问题的最…...

h5页面用js判断机型是安卓还是ios,判断有app安装没app跳转应用商店app stroe或者安卓应用商店

用vue3写的wep页面。亲测好使。 疑惑&#xff1a; 微信跳转和浏览器跳转不一样&#xff0c;需要控制定时器的时间&#xff0c;android在没下载的情况下点击没反应&#xff0c;ios在没下载的情况下会跳404&#xff0c;就是定时器2000&#xff0c;不知道有没有别的办法&#xff0…...

算法人生(17):从“课程学习”到“逐步暴露心理疗法”

课程学习&#xff08;Curriculum Learning&#xff09;是一种机器学习里常用的策略&#xff0c;它的灵感来源于人类学习方式&#xff1a;学习从简单的概念开始&#xff0c;逐步过渡到更复杂的问题。它通过模仿教育领域中课程安排的思想&#xff0c;设计了一系列有序的任务或数据…...

C++仿函数周边及包装器

我最近开了几个专栏&#xff0c;诚信互三&#xff01; > |||《算法专栏》&#xff1a;&#xff1a;刷题教程来自网站《代码随想录》。||| > |||《C专栏》&#xff1a;&#xff1a;记录我学习C的经历&#xff0c;看完你一定会有收获。||| > |||《Linux专栏》&#xff1…...

改进灰狼算法优化随机森林回归预测

灰狼算法&#xff08;Grey Wolf Optimization&#xff0c;GWO&#xff09;是一种基于自然界灰狼行为的启发式优化算法&#xff0c;在2014年被提出。该算法模仿了灰狼群体中不同等级的灰狼间的优势竞争和合作行为&#xff0c;通过不断搜索最优解来解决复杂的优化问题。 灰狼算法…...

Hadoop生态系统的核心组件探索

理解大数据和Hadoop的基本概念 当我们谈论“大数据”时&#xff0c;我们指的是那些因其体积、速度或多样性而难以使用传统数据处理软件有效管理的数据集。大数据可以来自多种来源&#xff0c;如社交媒体、传感器、视频监控、交易记录等&#xff0c;通常包含了TB&#xff08;太…...

命令行方式将mysql数据库迁移到达梦数据库(全步骤)

因项目需求&#xff0c;需要将mysql数据库转换为国产达梦数据库&#xff0c;但由于安全问题&#xff0c;正式环境只能用命令行方式连接&#xff0c;下列是操作全步骤 目录 一、操作逻辑二、操作步骤1、本地安装达梦相关工具2、将服务器mysql导出到本地a) 服务器命令行导出mysql…...

旅游系列之:庐山美景

旅游系列之&#xff1a;庐山美景 一、路线二、住宿二、庐山美景 一、路线 庐山北门乘坐大巴上山&#xff0c;住在上山的酒店东线大巴游览三叠泉&#xff0c;不需要乘坐缆车&#xff0c;步行上下三叠泉即可&#xff0c;线路很短 二、住宿 长江宾馆庐山分部 二、庐山美景...

杭州恒生面试,社招,3年经验

你好&#xff0c;我是田哥 一位朋友节前去恒生面试&#xff0c;其实面试问题大部分都是八股文&#xff0c;但由于自己平时工作比较忙&#xff0c;完全没有时间没有精力去看八股文&#xff0c;导致面试结果不太理想&#xff0c;HR说节后通知面试结果&#xff08;估计是凉了&…...

超短脉冲激光自聚焦效应

前言与目录 强激光引起自聚焦效应机理 超短脉冲激光在脆性材料内部加工时引起的自聚焦效应&#xff0c;这是一种非线性光学现象&#xff0c;主要涉及光学克尔效应和材料的非线性光学特性。 自聚焦效应可以产生局部的强光场&#xff0c;对材料产生非线性响应&#xff0c;可能…...

DeepSeek 赋能智慧能源:微电网优化调度的智能革新路径

目录 一、智慧能源微电网优化调度概述1.1 智慧能源微电网概念1.2 优化调度的重要性1.3 目前面临的挑战 二、DeepSeek 技术探秘2.1 DeepSeek 技术原理2.2 DeepSeek 独特优势2.3 DeepSeek 在 AI 领域地位 三、DeepSeek 在微电网优化调度中的应用剖析3.1 数据处理与分析3.2 预测与…...

Redis相关知识总结(缓存雪崩,缓存穿透,缓存击穿,Redis实现分布式锁,如何保持数据库和缓存一致)

文章目录 1.什么是Redis&#xff1f;2.为什么要使用redis作为mysql的缓存&#xff1f;3.什么是缓存雪崩、缓存穿透、缓存击穿&#xff1f;3.1缓存雪崩3.1.1 大量缓存同时过期3.1.2 Redis宕机 3.2 缓存击穿3.3 缓存穿透3.4 总结 4. 数据库和缓存如何保持一致性5. Redis实现分布式…...

江苏艾立泰跨国资源接力:废料变黄金的绿色供应链革命

在华东塑料包装行业面临限塑令深度调整的背景下&#xff0c;江苏艾立泰以一场跨国资源接力的创新实践&#xff0c;重新定义了绿色供应链的边界。 跨国回收网络&#xff1a;废料变黄金的全球棋局 艾立泰在欧洲、东南亚建立再生塑料回收点&#xff0c;将海外废弃包装箱通过标准…...

【碎碎念】宝可梦 Mesh GO : 基于MESH网络的口袋妖怪 宝可梦GO游戏自组网系统

目录 游戏说明《宝可梦 Mesh GO》 —— 局域宝可梦探索Pokmon GO 类游戏核心理念应用场景Mesh 特性 宝可梦玩法融合设计游戏构想要素1. 地图探索&#xff08;基于物理空间 广播范围&#xff09;2. 野生宝可梦生成与广播3. 对战系统4. 道具与通信5. 延伸玩法 安全性设计 技术选…...

蓝桥杯3498 01串的熵

问题描述 对于一个长度为 23333333的 01 串, 如果其信息熵为 11625907.5798&#xff0c; 且 0 出现次数比 1 少, 那么这个 01 串中 0 出现了多少次? #include<iostream> #include<cmath> using namespace std;int n 23333333;int main() {//枚举 0 出现的次数//因…...

微软PowerBI考试 PL300-在 Power BI 中清理、转换和加载数据

微软PowerBI考试 PL300-在 Power BI 中清理、转换和加载数据 Power Query 具有大量专门帮助您清理和准备数据以供分析的功能。 您将了解如何简化复杂模型、更改数据类型、重命名对象和透视数据。 您还将了解如何分析列&#xff0c;以便知晓哪些列包含有价值的数据&#xff0c;…...

Java 二维码

Java 二维码 **技术&#xff1a;**谷歌 ZXing 实现 首先添加依赖 <!-- 二维码依赖 --><dependency><groupId>com.google.zxing</groupId><artifactId>core</artifactId><version>3.5.1</version></dependency><de…...

从 GreenPlum 到镜舟数据库:杭银消费金融湖仓一体转型实践

作者&#xff1a;吴岐诗&#xff0c;杭银消费金融大数据应用开发工程师 本文整理自杭银消费金融大数据应用开发工程师在StarRocks Summit Asia 2024的分享 引言&#xff1a;融合数据湖与数仓的创新之路 在数字金融时代&#xff0c;数据已成为金融机构的核心竞争力。杭银消费金…...

通过 Ansible 在 Windows 2022 上安装 IIS Web 服务器

拓扑结构 这是一个用于通过 Ansible 部署 IIS Web 服务器的实验室拓扑。 前提条件&#xff1a; 在被管理的节点上安装WinRm 准备一张自签名的证书 开放防火墙入站tcp 5985 5986端口 准备自签名证书 PS C:\Users\azureuser> $cert New-SelfSignedCertificate -DnsName &…...