标点符号的消除及判断有无

#include <iostream>
#include <string>

using namespace std;

int main ()
{
string v1,result_str;
char xiao;
bool has_punct = false;

cout << "Enter a string: " << endl;

getline(cin,v1);

for(string::size_type index = 0; index != v1.size(); ++index)
{
xiao = v1[index];
if(ispunct(xiao))
has_punct = true;
else
result_str += xiao;
}

if(has_punct)
cout << "结果:" << endl << result_str << endl;//输出的结果中没有标点符号,只有字母,
else
cout << "在输入的字符串中没有发现标点符号!" << endl;

	return 0;
}

你可能感兴趣的:(标点符号的消除及判断有无)