我有一个字符串,我想从中删除所有标点符号.我怎么做?我做了一些研究,发现人们使用 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);
这篇关于C++ 从字符串中删除标点符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!