从string工具中去掉标点标记
编一个措施,从string 工具中去掉标点标记。要求输入到措施的字符串必需含有标点 标记,输出功效则是去掉标点标记后的string 工具。
消除标点
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main()
{
string s, result_str;
bool has_punct = false; //用于标志字符串中有无标点
char ch; //输入字符串
cout << "Enter a string:" << endl;
getline(cin, s); //处理惩罚字符串:去掉个中的标点
for (string::size_type index = 0; index != s.size(); ++index)
{
ch = s[index];
if (ispunct(ch))
has_punct = true;
else
result_str += ch;
}
if (has_punct)
cout << "Result:" << endl << result_str <<endl;
else
{
cout << "No punctuation character in the string?!" << endl;
return -1;
}
return 0;
}