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.
using namespace std;
int main(int argc,char *argv)
cout << "argument error" << endl;
ifstream file (argv, ios::in|ios::binary);
//ifstream fin( outfile, ios::in | ios::binary );
cout << "Can not open file";
unsigned char d;
file.read( ( char * ) &d, sizeof( unsigned char ) );
cout << d << endl;
First of all don't do
Then for your problem: It is that you output a character. That means the stream will attempt to print it as a character, which will not be correct for binary data.
If you want to print the values you read, you need to convert it to integers. Something like
std::cout << std::hex << std::setw(2) << std::setfill('0') << << static_cast<unsigned int>(d);
The above should print out the values as 2-digit hexadecimal numbers. The important bit is the