Reading file, endianess, int
Hello, everyone
I've wanted to start learning more about C++ after been in C# for about 2years.
So I wanted to do this new project into C++ instead, yet I'm struggling so much with such simple idiotic thing, but I can't wrap my head around.
I have a raw file..
Code:
41000000000000002A000000F4790100....
The very thing I want is to get the first 4 bytes and display as a int.
That means, show me "65"
I've tried countless things, but can't in a simple way
and the closest I got was using a for loop... definetly not on the simple side...
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
char b[4];
std::ifstream f("file",ios::binary);
f.seekg(0);
f.read(b,4);
cout << hex << b;
return 0;
}
This displays me "A" thats kinda right, but not what I want
I was expecting atleast 41, or 41000000 or 00000041
I've tried to cast it as (unsigned int)b, but then it display some random hex numbers..
What am I doing it wrong, is there a simple way to do this at all?
In c# i'd just use.
int i = b.ReadInt32();
//b being a binaryreader stream of the file.