当前位置:网站首页>Detailed Explanation of the Level 5 Test Center of the Chinese Institute of Electronics (1)-string type string
Detailed Explanation of the Level 5 Test Center of the Chinese Institute of Electronics (1)-string type string
2022-08-11 08:42:00 【mooczhimahu】
string definition
string is a string type in C++ that is better, faster, and simpler than char in most ways.
Define a variable of type string:
#includeusing namespace std;int main(){string s;}
string is the type used to store strings, different from char.The char variable can only store characters, and the chan array can store strings, but strings are designed to store strings.Each variable of the string type variable can store a string. The variable space (length) is determined by the characters stored in it, and there is no need to define it yourself.In addition, there are arrays of type string, which can store multiple strings.
The input and output of strings are simple, no different from int variables.
#includeusing namespace std;int main(){string s;cin>>s;//or s={a,b,c,d,e,f};cout<
Usage of string
1. Concatenate the two strings with a + sign;
#includeusing namespace std;int main(){string s1,s2;cin>>s1>>s2;s1=s1+s2;cout<
2. Test length, use size;
3. Take character:
string type string.substr(start subscript, length);
Start from the starting subscript, take a few characters.
#includeusing namespace std;int main(){string s1,s2;cin>>s2;s1=s2.substr(2,3);cout<
4. Delete:
string type string.erase(start subscript,length);
From the beginning of the string, delete a few characters.
#includeusing namespace std;int main(){string s1,s2;cin>>s2;s1=s2.erase(2,3);cout<
5. Insert:
string type string 1.insert (starting subscript, string type string 2);
Insert string type string 2 before the starting subscript of string type string 1.
#includeusing namespace std;int main(){string s1,s2;cin>>s1>>s2;s1.insert(2,s2);cout<
边栏推荐
- opengauss创建用户权限问题
- Keep track of your monthly income and expenses through bookkeeping
- 通过Xshell连接Vagrant创建的虚拟机
- 【43. 字符串相乘】
- Creo9.0 特征的成组
- gRPC系列(四) 框架如何赋能分布式系统
- dsu on tree(树上启发式合并)学习笔记
- One network cable to transfer files between two computers
- UNITY gameobject代码中setacvtive(false)与面板中直接去掉勾 效果不一样
- Redis 只会用缓存?20种妙用让同事直呼牛X(荣耀典藏版)
猜你喜欢
Unity3D - modification of the Inspector panel of the custom class
Creo9.0 特征的成组
excel 透视表 值显示内容 不显示计数
go-grpc TSL authentication solution transport: authentication handshake failed: x509 certificate relies on ... ...
golang string manipulation
IQUNIX A80 exploring TTC金粉 初体验
Features of LoRa Chips
零基础SQL教程: 基础查询 05
基于 VIVADO 的 AM 调制解调(3)仿真验证
【TA-霜狼_may-《百人计划》】图形3.7.2 command buffer简
随机推荐
基于C#通过PLCSIM ADV仿真软件实现与西门子1500PLC的S7通信方法演示
Filesystem Hierarchy Standard
SDUT 2877:angry_birds_again_and_again
Kotlin算法入门求回文数数算法优化二数字生成规则
基于 VIVADO 的 AM 调制解调(2)工程实现
redis operation
C语言-结构体
观察表情和面部,会发现他有焦虑和失眠的痕迹
Getting Started with Kotlin Algorithms Calculating Prime Factors
场地预订系统,帮助场馆提高坪效
为什么会没有内存了呢
关于架构的认知
Getting Started with Kotlin Algorithms Calculating Prime Numbers and Optimization
你有对象类,我有结构体,Go lang1.18入门精炼教程,由白丁入鸿儒,go lang结构体(struct)的使用EP06
js将table生成excel文件并去除表格中的多余tr(js去除表格中空的tr标签)
Creo9.0 特征的成组
万字长文带你了解多态的底层原理,这一篇就够了
shell之sed
Kotlin算法入门计算质因数
IQUNIX A80 exploring TTC金粉 初体验