in file "c++0x_warning.h". I just tried to ignore that error (simply used /* */on it) and it compiled just fine.. |
A better thing to do would be to do what the error suggested, and compile with the -std=c++0x compiler option.
An even better thing to do would be to update your compiler, as C++11 has been the standard for over a year now and GCC (which I assume you're using), has had very respectable support for quite some time.
(I just tried it since I thought signed and unsigned 32bit integers both represented an equal ammount of storage space and that I could therefore simply use the same function for saving both :/ (not sure if this can run into problems in the future though) |
That's fine. Really the only reason I separate signed/unsigned versions is for code clarity and to avoid having to cast back/forth between types. But if that doesn't bother you, then saving everything as unsigned will work just fine.
I'm also not sure how to save standard doubles (can I just enter and handle them in a standard 8 bytes funtion?) |
floating points are tricky for a few reasons. One is that the format they're stored in does not seem to be as clearly regulated as integral types. Another is that you can't extract raw, individual bytes from them without doing really ugly memory tricks.
For these reasons I pretty much always write them as strings. It's not ideal because it's a little slower than it could be, but it's easy and reliable. Something like this should work for you:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
void writedouble(ostream& fileout, double val)
{
stringstream s;
s << val;
writestring(fileout,s.str());
}
double readdouble(istream& filein)
{
double val = 0;
stringstream s( readstring(filein) );
s >> val;
return val;
}
|
If you'd rather not do it that way... and if you're not worried about endian issues, then doing a dumb read/write would work just fine:
1 2 3 4 5 6 7 8 9 10 11
|
void writedouble(ostream& fileout,double val)
{
fileout.write((char*)(&val), sizeof(val));
}
double readdouble(istream& filein)
{
double val;
filein.read((char*)(&val), sizeof(val));
return val;
}
|
But again note that this would be subject to system endianness and floating point storage mechanisms which may vary from machine to machine. However if these files are not going to survive past the end of the program, then that's a nonissue.
Also side note: I used the more generic 'ostream' and 'istream' classes in my examples above because it's less restrictive. No point in restricting yourself to only fstreams if you're not doing anything that's specific to fstreams. But that's a minor detail -- I'm sure it won't make a difference for you.