C++字符串相关操作函数

#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
*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值