How do you convert this java code of reading in a file to be in C++. Just trying to read a file in and then print the heading of the file. I can do it in Java but would like to have it in C++
f = new DataInputStream(new FileInputStream(directory + fileName));
int magic_num = f.readInt();
if (magic_num != 0xBBBBBAAD) {
f.close();
return(null);
}
int version = f.readInt();
fi.height = f.readInt();
fi.width = f.readInt();
int type = f.readInt();
fi.nImages = f.readInt();
fi.offset = f.readInt();
int flags = f.readInt();
System.out.println(">>ARF header: "+magic_num+" "+version+" "+fi.width+" "+fi.height+" "+type+" "+fi.nImages+" "+fi.offset);
This what I have go so far, but can not get it to print the correct data.
#include <iostream>
#include <fstream>
#include <inttypes.h>
using namespace std;
int main () {
streampos size;
char * memblock;
ifstream file ("/home/arf/0001.arf", ios::in|ios::binary|ios::ate);
if (file.is_open())
{
size = file.tellg();
memblock = new char [size];
file.seekg (0, ios::beg);
file.read (memblock, size);
file.close();
printf("%02x", memblock[0]);
delete[] memblock;
}
else cout << "Unable to open file";
return 0;
}