How to strip all non alphanumeric characters from a string in c++?

后端 未结 11 1473
野的像风
野的像风 2020-11-30 02:07

I am writing a piece of software, and It require me to handle data I get from a webpage with libcurl. When I get the data, for some reason it has extra line breaks in it. I

11条回答
  •  鱼传尺愫
    2020-11-30 02:31

    Previous uses of std::isalnum won't compile with std::ptr_fun without passing the unary argument is requires, hence this solution with a lambda function should encapsulate the correct answer:

    s.erase(std::remove_if(s.begin(), s.end(), 
    []( auto const& c ) -> bool { return !std::isalnum(c); } ), s.end());
    

提交回复
热议问题