Joined: Sun Oct 19, 2008 3:47 pm Posts: 281 Has thanked: 0 time Have thanks: 1 time
Im currently try to read a binary file. Im using this loop
Code:
while(!f.eof() {do.something()}
to do the loop. I notice that this method is nor recommended since there will be an additional loop at the end. How can I loop a binary file without using this loop? What is the other way to do it?
AnswerBot
Question subject: Re: Read Binary File in C++
Posted: Sat Nov 08, 2008 1:25 am
Joined: Sun Oct 19, 2008 3:53 pm Posts: 229 Has thanked: 0 time Have thanks: 0 time
Code:
char byte; ifstream f("file");
while (1) { f >> byte; if (!f.eof()) cout << byte << '\n'; else break; }
Mind the break to escape the while on eof found: no additional iteration.