天天看点

去掉字符串中的标点符号

#include <iostream>

#include <cctype>

#include <string>

using namespace std;

int main()

{

  cout<<"请输入字符串"<<endl;

  string s,result;

  cin>>s;

  bool haspunct=false;

  if(s.empty())

  {

    cout<<"您输入的字符串为空!请重新输入:"<<endl;

  }

  for(int i=0;i!=s.size();i++)

    if(ispunct(s[i]))

    {

      haspunct=true;

    }

    else

      result=result + s[i];

  if(haspunct==false)

    cout<<"您输入的字符串没有标点符号!"<<endl;

    return -1;

  else

    cout<<"去掉标点符号后为:"<<result;

  return 0;

}

继续阅读