Whats the most efficient way of removing a \'newline\' from a std::string?
Another way to do it in the for loop
void rm_nl(string &s) { for (int p = s.find("\n"); p != (int) string::npos; p = s.find("\n")) s.erase(p,1); }
Usage:
string data = "\naaa\nbbb\nccc\nffffd\n"; rm_nl(data); cout << data; // data = aaabbbcccffffd