How to remove newline from char *?

c++, newline, string

Solution

char *tmp = ...;

// the erase-remove idiom for a cstring
*std::remove(tmp, tmp+strlen(tmp), '\n') = '\0'; // removes _all_ new lines.

Problem

I've got a variable: `char * tmp` and I do few operations with it. Finally, I've got something like this `"fffff"` but sometimes before fffff is `"\n"`. How can I delete it?

Original source