在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
参考于https://blog.csdn.net/Hachi_Lin/article/details/79772451 1.strcat() strcat(字符数组1,字符数组2) 1 #include <bits/stdc++.h>
2 using namespace std;
3 int main() {
4 char str1[30], str2[20];
5 cout << "please input string1:" << endl;
6 cin >> str1;
7 cout << "please input string2:" << endl;
8 cin >> str2;
9 strcat(str1, str2);
10 cout << "Now the string is:" << endl;
11 cout << str1 << endl;
12 return 0;
13 }
运行结果:
2.strcpy() 1 #include <bits/stdc++.h>
2 using namespace std;
3 int main() {
4 char str1[30], str2[20];
5 cin >> str1; //给str1赋值
6 cout << "str1为:" << str1 << endl;
7 strcpy(str2, "456789"); //给str2赋值
8 cout << "str2为:" << str2 << endl;
9 strcpy(str1, str2);
10 cout << "str1为:" << str1 << endl;
11 return 0;
12 }
运行结果:
3.strcmp() 1 #include <bits/stdc++.h>
2 using namespace std;
3 int main() {
4 char str1[30], str2[30];
5 cin >> str1;
6 cout << "str1为:" << str1 << endl;
7 cin >> str2;
8 cout << "str2为:" << str2 << endl;
9 cout << strcmp(str1, str2) << endl;
10 return 0;
11 }
运行结果:
4.strncmp() 格式: 1 #include <bits/stdc++.h>
2 using namespace std;
3 int main() {
4 char str1[30], str2[30];
5 cin >> str1;
6 cout << "str1为:" << str1 << endl;
7 cin >> str2;
8 cout << "str2为:" << str2 << endl;
9 int n;
10 cin >> n;
11 cout << "n为:" << n << endl;
12 cout << strncmp(str1, str2, n) << endl;
13 return 0;
14 }
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论