当前位置:网站首页>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
边栏推荐
- Unity获取真实地理地图应用Terrain笔记
- 內網滲透系列:內網隧道之icmpsh
- 每天工作4小时的程序员
- 一文了解系列,对web渗透的常见漏洞总结(持续更新)
- When using flash, the code ends automatically without an error, the connection cannot be maintained, and the URL cannot be accessed.
- SAP sto with billing process and configuration
- 聊聊接口幂等与消费幂等的本质
- Complete learning from scratch, machine learning and deep learning, including theory and code implementation, mainly using scikit and mxnet, and some practices (on kaggle)
- 内网渗透系列:内网隧道之dnscat2
- 面试学习路线
猜你喜欢
![MySQL8. 0 installation / uninstallation tutorial [window10 version]](/img/9c/1acf153b410f0d2eb6a23dcdbabb88.png)
MySQL8. 0 installation / uninstallation tutorial [window10 version]

C#控制相机,旋转,拖拽观察脚本(类似Scenes观察方式)

Analysis of Nacos source code

Export all SVG files in the specified path into pictures in PNG format (thumbnail or original size)

Internal network security attack and defense: a practical guide to penetration testing (8): Authority maintenance analysis and defense

VBA調用SAP RFC實現數據讀取&寫入

The projection vector of a vector to a plane
![[NLP notes] preliminary study on CRF principle](/img/8c/2717aeee2e75bdae97d2bacd362e53.png)
[NLP notes] preliminary study on CRF principle

VBA调用SAP RFC实现数据读取&写入

内网渗透系列:内网隧道之icmpsh
随机推荐
Série de pénétration Intranet: icmpsh du tunnel Intranet
SAP Query增强开发介绍
Three minutes to teach you to use Houdini fluid > > to solve particle fluid droplets
Expression related to month, year and day in SVG
TA notes of Zhuang understand (VII) < Lambert + Phong + shadow + 3evcolor + Ao >
Simplify exporting to SVG data files and all images in SVG folder
Complete learning from scratch, machine learning and deep learning, including theory and code implementation, mainly using scikit and mxnet, and some practices (on kaggle)
Idea shortcut
FUEL: Fast UAV Exploration using Incremental Frontier Structure and Hierarchical Planning
MySQL in window10 version does not work after setting remote access permission
The projection vector of a vector to a plane
Online Safe Trajectory Generation For Quadrotors Using Fast Marching Method and Bernstein Basis Poly
05数组的使用
SAP GUI安全性
ABAP ALV显示金额与导出金额不一致
linux下mysql数据库备份与恢复(全量+增量)
庄懂的TA笔记(零)<铺垫与学习方法>
SAP tr manual import system operation manual
一些关于网络安全的好教程或笔记的链接,记录一下
Quick sort