#include <IOSTREAM>
using namespace std;
/*字符串相关操作函数:strcat、strcpy、strcmp、strupr、strlwr、strlen*/
void main()
{
char str0[100] = "This is a C++ program!";
char str1[10] = "So what!";
//strcat 字符串连接函数
strcat(str0,str1);
cout<<"str0:";
puts(str0);
//strcpy 字符串复制函数
strcpy(str0,str1);
cout<<"str0:";
cout<<str0<<endl;
cout<<"str0[12]:"<<str0[12]<<endl;
//strcmp 字符串比较函数
char str2[] = "So whas!";
cout<<strcmp(str1,"So what!")<<endl;
cout<<strcmp(str1,str2)<<endl;
cout<<strcmp(str1,"So waat!adff")<<endl;
cout<<strcmp(str1,"So wkat!")<<endl;
cout<<strcmp(str1,"So what!adff")<<endl;
//strupr 字符串全部转化为大写
strupr(str2);
puts(str2);
//strlwr 字符串全部转化为小写
strlwr(str2);
puts(str2);
//strlen 字符串长度(不包括字符串结束符'\0')
cout<<"str2的长度:"<<strlen(str2)<<endl;
}
/*
str0:This is a C++ program!So what!
str0:So what!
str0[12]:+
0
1
1
-1
-1
SO WHAS!
so whas!
str2的长度:8
Press any key to continue
*/
C++字符串相关操作函数
最新推荐文章于 2024-05-16 17:13:56 发布