C++:strcat、strcpy、strcmp、strupr、strlwr

#include <iostream>
#include <string>
using namespace std;
/*---------------------------------
字符串的常见处理函数
---------------------------------*/
void main()
{
	char a[20]="My name is ";  //a的空间大小定义为20,务必容纳下连接后的所有字符
	char b[]  ="jack";
	char c[]  ="jack";
	char d[]  ="ABCDEF";
	cout<<strcat(a,b)<<endl;   //返回a的指针 把字符串b连接到字符串a
	cout<<a<<endl;
	cout<<strcpy(a,b)<<endl;   //返回a的指针 把字符串b拷贝到字符串a
	cout<<a<<endl;
	if(0==strcmp(c,b))         //字符串大小比较
		cout<<"它们是相等的"<<endl;
	strupr(a);                 //小写字符转大写字符
	cout<<a<<endl;
	strlwr(d);                 //大写字符转小写字符
	cout<<d<<endl;
	cout<<"length of d[] is: "<<strlen(d)<<endl;
}
 
 
运行结果:
 
My name is jack
My name is jack
jack
jack
它们是相等的
JACK
abcdef
length of d[] is: 6

参考:
文章1
侵删

发布了3 篇原创文章 · 获赞 0 · 访问量 243

猜你喜欢

转载自blog.csdn.net/weixin_43991826/article/details/104881316
今日推荐