C++ Remove punctuation from String

后端 未结 12 2437
天涯浪人
天涯浪人 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:23

    Pretty good answer by Steve314. I would like to add a small change :

    text.erase (std::remove_if (text.begin (), text.end (), ::ispunct), text.end ());
    

    Adding the :: before the function ispunct takes care of overloading .

提交回复
热议问题