I try to read binary data by C++ program below. But it can not display values. The data is saved as 8bit unsigned char. Let me know how to solve it.
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc,char *argv[])
{
if(argc!=2)
{
cout << "argument error" << endl;
return 1;
}
ifstream file (argv[1], ios::in|ios::binary);
//ifstream fin( outfile, ios::in | ios::binary );
if (!file)
{
cout << "Can not open file";
return 1;
}
unsigned char d;
while(!file.eof())
{
file.read( ( char * ) &d, sizeof( unsigned char ) );
cout << d << endl;
}
file.close();
return 0;
}