Replace line breaks in a STL string
问题 How can I replace \r\n in an std::string ? 回答1: Use this : while ( str.find ("\r\n") != string::npos ) { str.erase ( str.find ("\r\n"), 2 ); } more efficient form is : string::size_type pos = 0; // Must initialize while ( ( pos = str.find ("\r\n",pos) ) != string::npos ) { str.erase ( pos, 2 ); } 回答2: don't reinvent the wheel, Boost String Algorithms is a header only library and I'm reasonably certain that it works everywhere. If you think the accepted answer code is better because its been