using namespace std; vector<char> buf; // fill data string res; copy_if(buf.begin(), buf.end(), back_inserter(res), [](char c){ return isprint(c) || isspace(c);});