当前位置:网站首页>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
边栏推荐
- Internal network security attack and defense: a practical guide to penetration testing (8): Authority maintenance analysis and defense
- About USB flash drive data prompt raw, need to format, data recovery notes
- Reading notes
- RGB color to hex and unit conversion
- Sto with billing cross company inventory dump return
- Analysis of Nacos source code
- Teach-Repeat-Replan: A Complete and Robust System for Aggressive Flight in Complex Environments
- SQL sorts string numbers
- 从零开始完整学习机器学习和深度学习,包括理论和代码实现,主要用到scikit和MXNet,还有一些实践(kaggle上的)
- VBA調用SAP RFC實現數據讀取&寫入
猜你喜欢

内网渗透系列:内网隧道之icmptunnel(jamesbarlow师傅的)

When using flash, the code ends automatically without an error, the connection cannot be maintained, and the URL cannot be accessed.

Research on software security based on NLP (I)

Sto with billing cross company inventory dump return

How does Apache Hudi accelerate traditional batch mode?

CTF攻防世界刷题51-

內網滲透系列:內網隧道之icmpsh

Chapter IV intangible assets

内网渗透系列:内网隧道之dnscat2

C#控制相机,旋转,拖拽观察脚本(类似Scenes观察方式)
随机推荐
VBA calls SAP RFC to read & write data
Unity C single case mode learning review notes
Buctf MISC brossage
【编程实践/嵌入式比赛】嵌入式比赛学习记录(二):基于TCP的图片流传输
SAP GUI security
TA notes of Zhuang understand (zero) < bedding and learning methods >
Série de pénétration Intranet: icmpsh du tunnel Intranet
一些靶场的学习记录:sqli-labs、upload-labs、XSS
BUUCTF MISC刷題
sentinel集成nacos动态更新数据原理
nacos源码分析思路
Learning records of some shooting ranges: sqli labs, upload labs, XSS
Houdini流体>>粒子流体导出到unity笔记
A programmer who works four hours a day
随笔(不定时更新)
CTF-MISC学习之从开始到放弃
Houdini fluid > > particle fluid export to unity note
Houdini>刚体, 刚体破碎RBD
SAP Query增强开发介绍
Unity get real geographic map application terrain notes