C++ 数组 4--字符串的常见处理函数strcat、strcpy、strcmp、strupr、strlwr

#include <iostream>
#include <string>
using namespace std;
/*---------------------------------
    14-33~39字符串的常见处理函数
---------------------------------*/
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
Press any key to continue

猜你喜欢

转载自blog.csdn.net/paulliam/article/details/80027413