C++ 从字符串中删除标点符号
我有一个字符串,我想从中删除所有标点符号.我怎么做?我做了一些研究,发现人们使用 ispunct() 函数(我试过了),但我似乎无法让它在我的代码中工作.有人有什么想法吗?
I got a string and I want to remove all the punctuations from it. How do I do that? I did some research and found that people use the ispunct() function (I tried that), but I cant seem to get it to work in my code. Anyone got any ideas?
#include <string>
int main() {
string text = "this. is my string. it's here."
if (ispunct(text))
text.erase();
return 0;
}
推荐答案
我明白了.
size_t found = text.find('.');
text.erase(found, 1);
相关文章