![]() |
|
Quick .dat question |
blargmob
Member #8,356
February 2007
![]() |
Howdy, OK, so I figured teh problem with my .dat files but I encountered another one. I am doing this: ofstream file; int noob=50; file.open("thingy.dat"); file << noob << endl;
Just to make teh file (test program) --- |
DanielH
Member #934
January 2001
![]() |
Just a heads up. On this site, dat files refer to datafiles created by the grabber. save PACKFILE *pfile = NULL; pfile = pack_fopen( "thingy.dat", "w" ); //, "wp" ); // if you want it packed pack_iputl( long value, pfile ); pack_fclose( pfile ); load PACKFILE *pfile = NULL; pfile = pack_fopen( "thingy.dat", "r" ); //, "rp" ); // if you want it packed long value = pack_igetl( pfile ); pack_fclose( pfile );
|
Johan Halmén
Member #1,550
September 2001
|
If you want to access variables from a file, you probably want to use config files. You can read/save variables from/to a config file. You have to rename the variables in the config file. Of course you can use same names as in your program, but that's not automatic. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest. |
Tobias Dammers
Member #2,604
August 2002
![]() |
Or, in case you are familiar with XML, you might consider TinyXML (but then, if you're not familiar with XML, or it's just a few single variables you need to save / load, XML is way overkill of course). You can, of course, use C++ iostreams to do the same thing, but there are some caveats: void put_long(ostream& out, int val) { out.put(val & 0xFF); out.put((val >> 8) & 0xFF); out.put((val >> 16) & 0xFF); out.put((val >> 24) & 0xFF); } int get_long(istream& in) { return (long)in.get() | ((long)in.get() << 8) | ((long)in.get() << 16) | ((long)in.get() << 24); } Don't make the common mistake to just write raw memory: fout.write((char*)(&my_struct), sizeof(my_struct));
Endianness and struct padding may break compatibility between platforms, compilers, or even builds. --- |
|