string类型操作

 
/*string的构造函数
*/
/*
#include<iostream>
using namespace std;
#include<string>
int main()
{
	string a(4,'c');
	string b("value");
	string c(b);
	cout<<a<<endl;
	cout<<b<<endl;
	cout<<c<<endl;
	//判断字符串是否为空
	if(!c.empty())
	{
		cout<<"c is not empty"<<endl;
//		string::size_type=c.size();
//		cout<<string::size_type<<endl;
	}
	//按照字符下标输出字符串
	cout<<c[4]<<endl;
	//字符串重载+号操作符
	c+=c;
	//字符串重载=操作符
	a=c;
	if(a==c)
	{
		cout<<"a is equal to c"<<endl;
	}
	cout<<a<<endl;
	cout<<c<<endl;
	string d;
	//输出带空格的字符串的方法
	getline(cin,d);
	cout<<d<<endl;
	//输出带空格后面的字符串的方法
	string e;
	while(cin>>e)
	{
		cout<<e;
	}
	return 0;
}
*/
/*字符串的赋值
*/
#include<iostream>
using namespace std;
#include<string>
int main()
{
	string s1="asdf";
	string s2="sefwe";
	string s3=s1+s2;
	string s4="asdfe"+s3;
	cout<<s4<<endl;
	cout<<s3<<endl;
	string::size_type si;
	for(si=0;si<s4.size();si++)
		cout<<s4[si]<<endl;
	if(isalnum(s4[4]))
	{
		cout<<"yes"<<endl;
	}
	if(isdigit(s4[4]))
	{
		cout<<"is digital"<<endl;
	}
	if(isupper(s4[4]))
	{
		cout<<"is upper alpher"<<endl;
	}
	for(si=0;si!=s4.size();si++)
	{
		s4[si]=toupper(s4[si]);
	}
	cout<<s4<<endl;
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值