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)
Printable View
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.
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
}