我有一个字符串,我想删除它的所有标点符号.我怎么做?我做了一些研究,发现人们使用ispunct()函数(我试过),但我似乎无法让它在我的代码中工作.有人有任何想法吗? #include stringint mai
#include <string>
int main() {
string text = "this. is my string. it's here."
if (ispunct(text))
text.erase();
return 0;
}
使用算法
remove_copy_if: –
string text,result;
std::remove_copy_if(text.begin(), text.end(),
std::back_inserter(result), //Store output
std::ptr_fun<int, int>(&std::ispunct)
);
