I am reading some text from another process through a pipe. The pipe returns the data to the variable chBuf
but contains lots of non-printable chars. I tried to remove these non-printable characters using erase and remove but throws an exception. The program works without this erase remove line. What may I doing wrong?
ReadFile(si->child_out_r, chBuf, BUFSIZE, &dwRead, NULL);
string s(chBuf);
s.erase(remove_if(s.begin(), s.end(), [](char c) { return !isprint((unsigned)c); }), s.end());
cout << s;