Hello everyone,
This is a pretty basic question, but I've been having no luck whatsoever in getting this to work.
Basically, I need to output long integers to a file - i.e. the 4 byte values, no formatting as text - as well as strings and other information. I know it's a basic question, but I honestly can find a way to to this. I'm trying to use 'ofstream', but if there's another class I should use please let me know.
Things I've tried:
outfile << myint;
This converts the value into a string rather than just writing the four byte value because the << formats it as text.
1 2 3 4 5 6
char myint2[4];
for(int i = 0; i < 4; i++)
{
myint2[i] = (char)(myint2 >> (3-i));
}
OutFile.write(myint2,4);
This outputs a strange value to the file. Not sure why.
Thanks everyone for the response. I don't think I paid enough attention to the tutorial when discussed casting. I'm going with reinterpret_cast<char*>(&myint), and it works.