从string对象中去掉标点符号

//编译器:GCC  4.2.1      环境:Redflag Linux 6.0 Desktop

    题目:编一个程序,从string对象中去掉标点符号。要求输入到程序的字符串必须含有标点符号,输出结果则是去掉标点符号后的string对象。

 

#include<iostream>
using namespace std;

string s,t;
string::size_type j=0,v=0,k,x=0;

int ifbd()
{
cout<<"Please input string s:"<<endl;
cin>>s;
for(k=0;k!=s.size();k++)
if(ispunct(s[k])) x++;
if(x!=0)            //判断s中的标点符号数是否为0
{
for(string::size_type i=0;i!=s.size();++i)
{
if(!ispunct(s[i]))        //判断s[i]是否为标点符号
{
t=t+s[i];
}
}
s=t;
cout<<s<<endl;
}
else
{
cout<<"There is none punctuation in s!"<<endl;
ifbd();            //如果s标点符号数为0则要求重新输入
}
}

int main()
{
ifbd();
}

posted @ 2008-10-13 11:47  mzlogin  阅读(911)  评论(0编辑  收藏  举报