I am attempting to read a binary file byte by byte, for some simple encryption-decryption program:
iftream f("a.in", ios::binary | ios::in);
ofstream g("a.out");
char x1, x2;
int x,j=0;
f.seekg(0);
f.get(&x1,sizeof(char));
while(!f.eof())
{
f.get(&x2,sizeof(char));
if(j==10)
{
g<<'\n';
j=0;
}
x=x1+x2;
x1=x2;
g<<x<<' ';
j++;
}
The code compiles, but the while() is stuck in an infinite loop, which is because the get() functions are not actually reading anything from the file.
I imagine it may be because of the dereferencing of the chars, but get() would only accept a pointer as its first argument.
Could anyone point out where I went wrong, please?