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

- Read structure from binary file

           typedef struct
           {
               int a;
               short b;
               char c;

           }Data;

           ...

           class::class()
           {
               fs.open("file.bin", ios::in | ios::binary);
           }

           int class::readstruct(Data *s)
           {
               bool b = fs.readK(s, sizeof(Data));

               cerr << "Reading " << (b ? "OK" : "Failed") << endl;
           }

- Write structure to binary file

           typedef struct
           {
               int a;
               short b;
               char c;

           }Data;

           ...

           class::class()
           {
               fs.open("file.bin", ios::out | ios::binary);
           }

           int class::writestruct(Data *s)
           {
               bool b = fs.writeK(s, sizeof(Data));

               cerr << "Writing " << (b ? "OK" : "Failed") << endl;
           }

  Note: remember, that reading and writing structures in binary mode is not doog idea. This is just example. See http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#7 and http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#3 for more.