For reading and writing data I use the following classes, inherited from ifstream and ofstream.
Class for reading binary data
class ifstreamK : public ifstream
{
    public:
	ifstreamK();

	Read 'size' bytes of binary data and store it into 'data'.
	Returns true if reading was successful, and false otherwise
	bool readK(void *data, int size);

        Read string from file
        bool getS(char *, const int);

        Read ascii hex value from file (like "0xFFFF00")
        bool readCHex(u32 &hex);

	big-endian-oriented reading
	bool be_getchar(u8 *c);
	bool be_getshort(u16 *s);
	bool be_getlong(u32 *l);
};

Class for writing binary data
class ofstreamK : public ofstream
{
    public:
	ofstreamK();

	bool writeK(void *data, int size);
};
Examples