c++之string(部分应用)

#include<iostream>
#include<cstring> 
using namespace std;
/*
strcpy(char[] dest,char[] src);	//拷贝src到dest,'/0'也被拷贝 
	strcmp(char[] s1,char[] s2);	//返回整型,相等则返回是0 
	strlen(char[] s);		//字符串长度,不算结尾的'/0' 
	strcat(char[] s1,char[] s2); //s2拼接到s1后
	strupr(char[]);		//字符串转大写
	strlwr(char[]);		//字符串转小写 
*/
 /*
 char s[100] = "test";
 for(int i = 0; s[i]; ++i){		//s[i] 作为判断条件 
	s[i] = s[i+1];
}
 */
void PrintSmall(char s1[],char s2[])
{
	if(strcmp(s1,s2) <= 0)	//strcmp,如果s1 <= s2 
		cout<<s1<<endl;
	else
		cout<<s2<<endl;
}
int main()
{
	 char s1[30]; char s2[40]; char s3[100];
	 
	 strcpy(s1,"I love You");	//拷贝 "I love You!"到 s1
	 
	 strcpy(s2,s1);
	 
	 cout<<"1) "<<s2<<endl;
	 
	 strcat(s1,",HXSLY");	//连接 "HXSLY" 到s1尾部
	 cout<<"2) "<<s1<<endl;
	 
	 cout<<"3) ";
	 PrintSmall("abc",s2);
	 cout<<endl;
	 
	 cout<<"4) ";
	 PrintSmall("abc","aaa");
	 cout<<endl; 
	 
	 int n = strlen(s2);	//求s2长度
	 cout<<"5) "<<n<<","<<strlen("abc")<<endl;//输出两个整数
	 
	 strupr(s1);
	 cout<<"6) "<<s1<<endl;
	 
	 strlwr(s1);
	 cout<<"7) "<<s1<<endl; 
	 
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值