C++ Remove punctuation from String

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

    Using algorithm remove_copy_if :-

    string text,result;
    std::remove_copy_if(text.begin(), text.end(),            
                            std::back_inserter(result), //Store output           
                            std::ptr_fun(&std::ispunct)  
                           );
    

提交回复
热议问题