C++primer 3 string

#include <iostream>
#include <string>
using namespace std;

int main()
{
	//统计标点符号的个数
	/*
	string s("!af,yu,jf!!!");
	string::size_type a=0;
	for(string::size_type i=0;i<=(s.size()-1);++i)
		if(ispunct(s[i]))
			a=a+1;
	cout<<a<<endl;
    cout<<isspace(s[0])<<endl;
    */
	//比较字符串的大小和长度
	/*
	string s1,s2;
	s1="ASD";
	s2="asd";

	if(s1!=s2)
	{
		if(s1>s2)
			cout<<s1<<endl;
		else
			cout<<s2<<endl;
	}
	else
	{
		cout<<"s1==s2"<<endl;
	}
	if(s1.size()!=s2.size())
	{
		if(s1.size()>s2.size())
			cout<<"s1="<<s1<<" longer"<<endl;
		else
			cout<<"s2="<<s2<<" longer"<<endl;
	}
	else
		cout<<"s1="<<s1<<" is as long as "<<"s2="<<s2<<endl;
	*/
	//从标准输入读取多个 string 对象,把它们连接起来存放到一个更大的 string 对象中。并输出连接
	//后的 string 对象。接着,改写程序,将连接后相邻 string 对象以空格隔开。
	/*
	string str ,result_str;
	cin>>result_str;
	while(cin>>str)
		//result_str+=str;
		result_str=result_str+' '+str;
	cout<<result_str<<endl;
	*/
	//从 string 对象中去掉标点符号。要求输入到程序的字符串必须含有标点符号,输出结果则是去掉标
	//点符号后的 string 对象
	/*
	string s;
	s="fda,dh!!,ddf!";
	cout<<s<<endl;
	string s_temp;
	for(string::size_type i=0;i<=s.size()-1;++i)
	{
		if(!ispunct(s[i]))
			s_temp=s_temp+s[i];
	}
	cout<<s_temp<<endl;
	s=s_temp;
	cout<<s<<endl;
	*/

	system("pause");
	return 1;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值