#include<iostream> #include<string> using namespace std; int main() { string str="atfi,,ie,,,idfi,,,oo"; decltype(str.size()) n=0; for(auto c:str) { if(!ispunct(c)) { str[n]=c; n++; continue; } else continue; } while(n!=str.size()) str[n++]='\0'; cout<<str<<endl; return 0; }
运行结果如下:

本文介绍了一个简单的C++程序,该程序通过遍历字符串并忽略所有标点符号来清除字符串中的标点符号。最终输出不含任何标点的纯净字符串。

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



