About parsing data from files opened in binary mode.

I'd like to read and write data to/from files in binary mode.
I have to use a char buffer and then how can I use this data?

I know that I have 1 long, 2 doubles, a string of 7 chars, etc....

Can anybody give some indications about pointers and how to use it to read -write data from buffers?
Thanks



A test program;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
int main(int argc, char *argv[]) 
{

    const int arraySize=7;
    fstream iofile;
    long ll = 2048;
    double dd = 123.789;
    char cc[arraySize]="Hello!";

    //open the file and write some data
    iofile.open("data.bin", ios::binary|ios::out|ios::trunc);
    iofile.write( (char*)&ll, sizeof(ll) );
    iofile.write( (char*)&dd, sizeof(dd) );
    iofile.write( cc, arraySize );

    iofile.close();

    
    //reset the variables.
    ll=0;
    dd=0;
    cc[0]='\0';

    //read back the data and check ok
    iofile.open("data.bin", ios::binary|ios::in);
    iofile.read( (char*)&ll, sizeof(ll) );
    iofile.read( (char*)&dd, sizeof(dd) );
    iofile.read( cc, arraySize );

    iofile.close();

}
 
Thank you very much !
Topic archived. No new replies allowed.