C++ examples for File Stream:stream
Reads person object from disk
#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; }