当前位置:网站首页>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<
边栏推荐
- pycharm中绘图,显示不了figure窗口的问题
- 基于C#通过PLCSIM ADV仿真软件实现与西门子1500PLC的S7通信方法演示
- Break pad source code compilation--refer to the summary of the big blogger
- golang string manipulation
- Swagger简单使用
- 观察表情和面部,会发现他有焦虑和失眠的痕迹
- AcWing 272. 最长公共上升子序列
- 为什么会没有内存了呢
- Kotlin算法入门求回文数算法优化一
- Getting Started with Kotlin Algorithm to Calculate the Number of Daffodils
猜你喜欢
随机推荐
向日葵安装教程--向日葵远程桌面控制
Openlayers 聚合图、权重聚合图以及聚合图点击事件
Initial use of IDEA
gRPC系列(四) 框架如何赋能分布式系统
Analysys and the Alliance of Small and Medium Banks jointly released the Hainan Digital Economy Index, so stay tuned!
AcWing 272. 最长公共上升子序列
Filesystem Hierarchy Standard
Rust从入门到精通06-函数
抽象类和接口
Machine Learning Summary (2)
《价值》读书与投资
gRPC系列(二) 如何用Protobuf组织内容
【云原生】云原生在网络安全领域的应用
通过Xshell连接Vagrant创建的虚拟机
nodejs微服务中跨域,请求,接口,参数拦截等功能
Kaldi语音识别工具编译问题记录(踩坑记录)
SDUT 2877:angry_birds_again_and_again
为什么会没有内存了呢
AUTOSAR从入门到精通番外篇(八)-C语言常用技巧50个
OAuth Client默认配置加载