I'm trying to show all the bytes in a .DAT file. I'm completely new to programming and I managed to find how to display the file size correctly but every output byte that I get are 0s even if in HxD the bytes aren't all zero.
What I get:
size is: 11
0000000000000000000000
What I should get:
size is: 11
48656C6C6F20776F726C64
Code:
#include <iostream>
#include <fstream>
#include <vector>
#include <fstream>
#include <iterator>
#include <iomanip>
using namespace std;
int main () {
//open file and get size
streampos begin,end;
ifstream myfile ("TRPTRANS.DAT", ios::binary);
begin = myfile.tellg();
myfile.seekg (0, ios::end);
end = myfile.tellg();
int n;
n=(end-begin);
cout << "size is: " << n<<endl;
//read file
vector<char> randomBytes(n);
myfile.read(&randomBytes[0], n);
//display bytes
for (auto& el : randomBytes)
cout << setfill('0') << setw(2) << hex << (0xff & (unsigned int)el);
cout << '\n';
return 0;
}
Can someone help me fix this and show the bytes correctly thanks