我有一个字符串,我想从中删除所有标点符号。我怎么做?我做了一些研究,发现人们使用 ispunct() 函数(我试过了),但我似乎无法让它在我的代码中工作。有人有什么想法吗?
#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)
);
关于C++从字符串中删除标点符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19138983/