This is my first post so sorry if I break any unwritten rules. :P I am a beginner/intermediate programmer and I need help with this program.
I am trying to infile/read/ifstream (whatever) a .dat file as HEX into one big string.
I don't want to read it as text. I want the hex format so I can search through the string and make changes to it. (Like an automatic hex editor)
ex. my file "00000000.dat" is ~7kb in size.
In hex editor, the hex look like this:
0A 00 00 0A 00 05 4C 65 76 65 6C 07 00 06 42 6C 6F 63 6B 73 00 00 80 00 07 FF 39
01 FF 03 03 02 FF 3F 00 07 FF 39 01 FF 03 03 02 FF 3F 00 07 FF 39 01 FF 03 03 02
FF 3F 00 07 FF 39 01 FF 03 03 02 FF 3F 00 07 FF 39 01 FF 03 03 02 FF 3F 00 07 FF
39 01 FF 03 03 02 FF 3F 00 07 FF 39 01 FF 03 03 02 FF 3F 00 07 FF 39 01 FF 03 03
02 FF 3F 00..... for a while...
I need all of it in a string variable (with no spaces preferably).
My current code sucks and for now only prints the result. (got it from ehow) and seems to pick and choose what it wants to input/print.
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
int main()
{
ifstream input;
input.open("00000000.dat");
unsigned char h1,h2;
do
{
input >> h1;
cout << hex << (unsigned int)h1;
input >> h2;
cout << hex << (unsigned int)h2;
}while(!input.eof());
cin.get();
return 0;
}
It's a big file so I can't show yo what it prints, but it is missing some bytes. (ex "0A 00 00 0A 00 05....." prints as "00 05.....") this is true for the ending as well.
Sorry if I didn't explain it well :(