当前位置:网站首页>strcat()、strcpy()、strcmp()、strlen()
strcat()、strcpy()、strcmp()、strlen()
2022-04-23 07:59:00 【Five five six six 0524】
const The value of the modified variable or object remains unchanged , Protect the contents of variables or objects from being modified during invocation
1、 String concatenation function strcat
The function prototype is strcat(char[],const char[])
The first 2 Declared as an array of characters const, To ensure that the contents of the array will not be modified during the function call
that , Why not put the second 1 An array of characters is also declared as const Well ?
In order to make 2 The contents of the first array overwrite the... At the end of the first array '\0', The sign of whether the string ends is '\0' The location of , If an array contains more than one '\0', You encounter the first '\0' When it's over
#include <iostream>
using namespace std;
int main() {
char a[30]="i love ";// Make sure the array is long enough to accommodate two plus
char b[] = "china";
cout << strcat(a, b)<< endl;
return 0;
}
2、 String copy function strcpy
The function prototype strcpy(char[],const char[])
The first 2 An array of characters does not change , Will be the first 1 The corresponding characters in the character array are overwritten
#include <iostream>
using namespace std;
int main() {
char a[100];
char b[] = "i love china";
strcpy(a, b);
cout << a<< endl;
return 0;
}
3、 String comparison function strcmp
The function prototype strcmp(const char[],const char[])
The purpose is to compare these two strings , Therefore, we should only compare and not change
The preceding string > String after , A positive number , Ahead < hinder , The value is negative. , Ahead = hinder , The value is 0
#include <iostream>
using namespace std;
int main() {
char a[] = "i love china";
char b[] = "i love";
cout << strcmp(a,b) << endl;
return 0;
}
4、 String length function strlen
The function prototype strlen(const chat[])
Actual length , barring '\0', Errors may be reported in the application : Not added for string 0 Terminator , Just initialize the string , Such as char str[100]={0}
#include <iostream>
using namespace std;
int main() {
char a[] = "i love china";
cout << strlen(a) << endl;
return 0;
}
版权声明
本文为[Five five six six 0524]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230628472043.html
边栏推荐
- Plane definition - plane equation
- IT高薪者所具备的人格魅力
- Reptile learning notes, learning reptile, read this article is enough
- VBA调用SAP RFC实现数据读取&写入
- Chapter IV intangible assets
- 常用Markdown语法学习
- MySQL8. 0 installation / uninstallation tutorial [window10 version]
- KCD_ EXCEL_ OLE_ TO_ INT_ Convert reports an error sy subrc = 2
- Export all SVG files in the specified path into pictures in PNG format (thumbnail or original size)
- Introduction to sap query enhanced development
猜你喜欢

MySQL--锁的奥秘--数据怎么锁

Unity get real geographic map application terrain notes

Chapter VII asset impairment

Online Safe Trajectory Generation For Quadrotors Using Fast Marching Method and Bernstein Basis Poly

Ribbon启动流程

Buctf MISC brossage

CTF-MISC学习之从开始到放弃

SAP self created table log function is enabled

随笔(不定时更新)

Protobuf use
随机推荐
聊聊接口幂等与消费幂等的本质
SAP TR手动导入系统操作手册
SAP STO With Billing流程与配置
The problem of exporting excel form with wireframe and internal spacing of form by using web form
How to present your digital portfolio: suggestions from creative recruiters
一些靶场的学习记录:sqli-labs、upload-labs、XSS
Post of experience in preparation for guarantee and research -- the 18th (2021) Central South planning department promoted the exemption to Zhejiang University Institute of Technology
Personality charm of high paid it workers
内网渗透系列:内网隧道之dns2tcp
Internal network security attack and defense: a practical guide to penetration testing (VII): cross domain attack analysis and defense
Houdini>刚体, 刚体破碎RBD
Robust and Efficient Quadrotor Trajectory Generation for Fast Autonomous Flight
Enterprise wechat login free jump self built application
The displayed amount of ABAP ALV is inconsistent with the exported amount
Gets the maximum getmaxpoint in the list of all points
Houdini流体>>粒子流体导出到unity笔记
Mysql database backup and recovery under Linux (full + incremental)
Unity gets a resource that is referenced by those resources
nacos源码分析思路
Unable to process jar entry [module info. Class]