I/O OPERATIONS ON BINARY FILES // read() & write()

Home Forums C++ I/O OPERATIONS ON BINARY FILES // read() & write()

This topic contains 0 replies, has 1 voice, and was last updated by  admin 2 weeks, 3 days ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #5252

    admin
    Keymaster

    // I/O OPERATIONS ON BINARY FILES
    // read() & write()
    #include <iostream.h>
    #include <fstream.h>
    #include <iomanip.h>
    const char * filename =”Binary”;
    int main()
    {
    float height[4] ={ 175.5,153.0,167.25,160.70};
    ofstream outfile;
    outfile.open(filename);
    outfile.write((char *) & height,sizeof(height));
    outfile.close();
    for (int i=0;i<4;i++)
    height[i]=0;
    ifstream infile;
    infile.open(filename);
    infile.read ((char *) & height,sizeof (height));
    for (i=0;i<4;i++)
    {
    cout.setf(ios::showpoint);
    cout<<setw(10)<<setprecision(2)<<height[i];
    }
    infile.close();
    return 0;
    }

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.