C++ Remove punctuation from String

后端 未结 12 2435
天涯浪人
天涯浪人 2020-11-29 07:02

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

12条回答
  •  失恋的感觉
    2020-11-29 07:38

    The problem here is that ispunct() takes one argument being a character, while you are trying to send a string. You should loop over the elements of the string and erase each character if it is a punctuation like here:

    for(size_t i = 0; i

提交回复
热议问题