
Remove newlines from string
Quote:
> Hi
> What is the "right" and effective way to remove all newlines from a stl string?
Hi Martin,
I think this is a good way:
// -----8<-----
#include <algorithm> // remove
#include <string>
#include <iostream>
using namespace std;
int main()
{
string s("first line \nsecond line \nthird .. \n***\n");
cout << "before: " << s << endl;
s.erase( remove( s.begin(), s.end(), '\n' ), s.end() );
cout << "after : " << s << endl;
return( 0 );
Quote:
}
// -----8<-----
Greetings
Werner