Error in reading a file? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Error in reading a file?

I want to clone a text file (ie. to make a new file with all the text in the same format as in the original file) using an ifstream read the file one character at a time, but it skipped all the blank spaces and new line. how can i make it read new line character and blank spaces.

29th Dec 2019, 2:49 PM
Chetan Satpute
Chetan Satpute - avatar
1 Answer
+ 1
Hi Chetan-Satpute Try something like: char ch; fstream fin("file", fstream::in); while (fin >> noskipws >> ch) { cout << ch; //Or write ch to a file } The key here is to unset the flag skipws. I think you could do the same easily using the function get().
30th Dec 2019, 6:30 PM
Mark