Since,binary file do not store special character(ascii no 26) for end of file.Then is it safe to use
If not then what should I use?Code:while(fileobj.peek!=EOF)
This is a discussion on Binary files within the C++ Programming forums, part of the General Programming Boards category; Since,binary file do not store special character(ascii no 26) for end of file.Then is it safe to use Code: while(fileobj.peek!=EOF) ...
Since,binary file do not store special character(ascii no 26) for end of file.Then is it safe to use
If not then what should I use?Code:while(fileobj.peek!=EOF)
I'm not exactly clear as to what you're asking. If you want to read in data until the end of the file is reached, you could use:
Or you could read one char at a time:Code:while (fileobj.read(array, sizeof(array)) { //Do something with array }
Code:while (fileobj.get(ch)) { //Do something with ch }
> If not then what should I use?
You examine the return status of file reading functions to determine whether you reached end of file, or some other error.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I support http://www.ukip.org/ as the first necessary step to a free Europe.
I just want to ask is it correct to use following loop termination in case of a binary file
Code:ifstream obj; obj.open("file.dat",ios::binary); while(obj.peek()!=EOF) { //Do some operation on each record }