如何从char*中删除换行符?

ruh*_*gry 3 c++ string newline

我有一个变量:char * tmp我用它做了很少的操作.最后,我有这样的事情"fffff"但有时候在fffff之前"\n".我该如何删除它?

bam*_*s53 6

char *tmp = ...;

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