I wrote a program that out puts a binary file. I have another program that reads in the binary file. I cannot get back the original data. How would I get back to the original data.

I am using the following to read the binay file

char buffer[4];

while(!infile.eof)
{

infile.read((char *) &z, sizeof(z));
cout << z << endl;

}

???? please help.
I keep getting back garbage.

Thanks.