Возможно что-то вроде:
struct InvalidChar
{
bool operator()(char c) const {
return !isprint(static_cast<unsigned char>(c));
}
};
std::string s;
HypoteticalReadFileToString(&s);
s.erase(std::remove_if(s.begin(),s.end(),InvalidChar()), s.end());
Лучше определить функцию многократного использования для идиомы стирания-удаления
template <typename C, typename P>
void erase_remove_if(C& c, P predicate) {
c.erase(std::remove_if(c.begin(), c.end(), predicate), c.end());
}
...
erase_remove_if(s, InvalidChar());