当前位置:网站首页>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< 
边栏推荐
- 研发了 5 年的时序数据库,到底要解决什么问题?
- 万字长文带你了解多态的底层原理,这一篇就够了
- 基于C#通过PLCSIM ADV仿真软件实现与西门子1500PLC的S7通信方法演示
- excel将数据按某一列值分组并绘制分组折线图
- Alibaba Sentinel - Slot chain解析
- go-grpc TSL authentication solution transport: authentication handshake failed: x509 certificate relies on ... ...
- 优炫数据库支持多列分区吗?
- Kotlin算法入门求自由落体
- @RequiredArgsConstructor注解
- 【C语言】每日一题,求水仙花数,求变种水仙花数
猜你喜欢

研发了 5 年的时序数据库,到底要解决什么问题?

Alibaba Sentinel - Slot chain解析

IQUNIX A80 exploring TTC金粉 初体验

Machine Learning Summary (2)

Mysql JSON对象和JSON数组查询

Analysys and the Alliance of Small and Medium Banks jointly released the Hainan Digital Economy Index, so stay tuned!

零基础SQL教程: 基础查询 05

pycharm中绘图,显示不了figure窗口的问题

设置Vagrant创建的虚拟机名称和内存

机器学习(一)数据的预处理
随机推荐
for循环和单击相应函数的执行顺序问题
js将table生成excel文件并去除表格中的多余tr(js去除表格中空的tr标签)
机器学习(二)线性回归
IDEA的初步使用
gRPC系列(一) 什么是RPC?
matplotlib
【43. 字符串相乘】
opengauss创建用户权限问题
go sqlx 包
高德能力API
一根网线两台电脑传输文件
抽象类和接口
【实战系列】OpenApi设计规范
Mysql JSON对象和JSON数组查询
基础SQL——DDL
框架外的PHP读取.env文件(php5.6、7.3可用版)
tensorflow 基础操作1(tensor 基本属性 , 维度变换,数学运算)
picker选择器出现object解决办法
【云原生】云原生在网络安全领域的应用
Filesystem Hierarchy Standard