Codeplug, note that the first version used a char, while the second used an int. Consider the following test program.
Code:
#include<iostream>
#include<fstream>
#include<ctype.h>
using namespace std;
void printquote(unsigned char c) {
char tbl[] = "0123456789ABCDEF";
if(isprint(c) || isspace(c)) {
cout << c;
} else {
cout << "\\0x" << tbl[(c>>4)&0x0F] << tbl[c & 0x0F];
}
}
int main() {
ofstream tmp("tmp",ios_base::trunc | ios_base::out);
tmp << (char)4 << " after unix eof char" << endl;
tmp << (char)EOF << " after iostream's EOF" << endl;
tmp << (char)26 << " after DOS eof char" << endl;
tmp.close();
cout << "with char (in binary mode)" << endl;
{
ifstream in("tmp",ios_base::binary);
char ch;
while((ch=in.get())!=EOF) printquote(ch);
}
cout << "with int (in binary mode)" << endl;
{
ifstream in("tmp",ios_base::binary);
int ch;
while((ch=in.get())!=EOF) printquote(ch);
}
cout << "with iostream state (in text mode)" << endl;
{
ifstream in("tmp");
char ch;
while(in.get(ch)) printquote(ch);
}
return 0;
}
the printquote is needed, because sending the dos eof char to cout (under dos) results in wackyness, plus it's a lot easyer to read. The point is that in.get() is just as "aggresive" as read() when the file is in binary mode. Actually I am not sure what the point is but I spent so much time playing with the odd behaviour of sending ^z down cout it seems like a shame not to post.
edit: possibly confusing this was not a reply to the OP scrambled posting.