0

How can i read from file in cpp?

For example when i write: while (!p0.eof()) to read from file the program just reads the first record and shows it? please see code 6

14th Jan 2017, 9:43 PM
Reza Sabralipour
Reza Sabralipour - avatar
1 Odpowiedź
0
do you have p0>>inputElement; before you re-iterate the loop? if not it would only take in the first one. #include <fstream> ifsteam file; file.open("fileName.txt"); //assuming this text file is in the same directory //of this file. int tempInput; while(!file.eof()){ file>>tempInput; //do stuff with info } //goes until end of file. this should work
23rd Feb 2017, 7:15 PM
Michael Szczepanski
Michael Szczepanski - avatar