Hi.
I am trying to read .dat files which is in binary using visual C++ 6.0. I want to display the first 100 char (in hex). But instead some weird char are being display. I opened the file through hex editor and this is what i am supposed to get: 2EFACCF69FFC84. ..
Can anyone help me in this? Thanks in advance!
I am trying to read .dat files which is in binary using visual C++ 6.0. I want to display the first 100 char (in hex). But instead some weird char are being display. I opened the file through hex editor and this is what i am supposed to get: 2EFACCF69FFC84. ..
Can anyone help me in this? Thanks in advance!
Code:
char *memblock;
ifstream::pos_type size;
ifstream file;
int main ()
{
int size, i;
char n;
file.open ("s0455_re.dat", ios::in|ios::binary|ios::ate);
if (file.is_open())
{
cout << "Able to open file!";
// Able to get the size since it is at the end
size = (int) file.tellg();
// allocate memory
memblock = new char [size];
file.seekg (0, ios::beg);
for (i=0; i<100; i++)
{
file.seekg (0, ios::cur);
file.read (memblock, 1);
n = *memblock;
cout << n;
}
file.close();
}
else cout << "Unable to open file";
return 0;
}
Comment