Instream & outstream
So when you reading a file, char by char, how can you use a void function to remove all the white-space? How about at the start and at the end of the text. Purpose: remove white-space “Test1.dat” input file text “ Hello World 123 4567 “ “translated.dat” output file support to be “Hello World 123 4567” no space at begin and end #include <iostream> #include <fstream> using namespace std; void remove_blanks(ifstream& in_stream); int main() { const char INFILE[] = "test1.dat"; const char OUTFILE[] = "translated.dat"; char next; // get next char in file // setup input file stream fin.open(INFILE); if (fin.fail()) { cout << "Cannot open file\n"; exit(1); } // setup output file stream ofstream fout; fout.open(OUTFILE); if (fout.fail()) { cout << "Input file cannot be opened\n"; exit(1); } fin.get(next); while (! fin.eof()) { if (isspace(next)) { remove_blanks(fin); } fout.put(next); fin.get(next); } // end of file loop cout << "End of editing files.\n" << "Check translated.dat for result!" << endl; // close streams fin.close(); fout.close(); return 0; } void remove_blanks(ifstream& in_stream) { char symbol; in_stream.get(symbol); while (isspace(symbol)) { in_stream.get(symbol); } in_stream.putback(symbol); //error here it keep loop back to put back last char so file can’t end of file return;