Reads person object from disk - C++ File Stream

C++ examples for File Stream:stream

Description

Reads person object from disk

Demo Code

#include <fstream>
#include <iostream>
using namespace std;
class person/*from  www  . ja  va  2 s .c om*/
{
   protected:
   char name[80];              //person's name
   short age;                  //person's age
   public:
   void showData()             //display person's data
   {
      cout << "Name: " << name << endl;
      cout << "Age: " << age << endl;
   }
};
int main()
{
   person pers;
   ifstream infile("PERSON.DAT", ios::binary); //create stream
      //read stream
   infile.read( reinterpret_cast<char*>(&pers), sizeof(pers) );
   pers.showData();
   return 0;
}

Related Tutorials