//modified by quanspace
/*从string对象中去掉标点符号。要求输入到程序中滴字符串必须含有
* 标点符号,输出结果则是去掉标点符号后的string 对象。
* */
# include <iostream>
# include <string>
using namespace std;
int main(){
string str = "enjoy ?><..coding, enjoy,.*@ playing!";
string::size_type i;
cout<<"the original string : "<<endl;
cout<<str<<endl;
cout<<"delete punctuation of the strings :"<<endl;
for(i = 0; i< str.size(); ++i){//ispunc() 是判断字符串中是否有标点符号
if(!ispunct(str[i]))
cout<<str[i];
}
cout<<endl;
return 0;
}

本文介绍了一种从字符串中删除所有标点符号的方法。通过使用C++编程语言,我们展示了如何遍历字符串并利用标准库函数ispunct()来判断并移除每个标点符号,最终输出不含标点符号的字符串。

被折叠的 条评论
为什么被折叠?



