c++ 去掉所有空格及换行符

 string get_string(string res){

  //删除换行符

  int r = res.find('\r\n');
  while (r != string::npos)
  {
    if (r != string::npos)
    {
      res.replace(r, 1, "");
      r = res.find('\r\n');
    }
  }

  //删除所有空格

  res.erase(std::remove_if(res.begin(), res.end(), std::isspace), res.end());

  return res;

}


posted @ 2019-11-14 15:32  不知起什么名字  阅读(8899)  评论(0编辑  收藏  举报