Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WRITING THEN READING MULTIDIMENSIAL ARRAY

Status
Not open for further replies.

blackened789

Programmer
Oct 15, 2011
2
PH
HOW DO YOU WRITE IN A .BIN FILE AN ARRAY WITH THE FOLLOWING SPECS:

double A[12[17];

THEN HOW DO YOU READ THE FILE SO YOU ARE ABLE TO GET BACK THE DATA?
 
What's a problem?
Code:
    double a[12][17];
    int     b[40];
    ... // populate a, b...
    const char* fname = "xxxx.xxx";
    std::ofstream fout(fname,std::ios::binary);
    fout.write((const char*)a,sizeof a);
    fout.write((const char*)b,sizeof b);
    fout.close();
then
Code:
    ...
    std::ifstream fin(fname,std::ios::binary);   
    fin.read((char*)a,sizeof a);
    fin.read((char*)b,sizeof b);
    fin.close();
or (non-stop)
Code:
    std::fstream f(fname,std::ios::binary);
    f.write((const char*)a,sizeof a);
    f.write((const char*)b,sizeof b);
    ...
    f.seekg(0); // rewind op
    f.read((char*)a,sizeof a);
    f.read((char*)b,sizeof b);
    ...
    f.close();
Add error checking and go on!..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top