X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f Message-ID: <20040904180941.51563.qmail@web20223.mail.yahoo.com> Date: Sat, 4 Sep 2004 11:09:41 -0700 (PDT) From: pradyut bhattacharya Subject: file I/O To: djgpp AT delorie DOT com MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii i have written on object I/O the code : - ---------------------------------------------------------------------------------------------- #include #include using namespace std; class student { private: int iReg_no; char cName[20]; public: void setRegno() { cout <<"\nEnter the Registration number: "; cin >>iReg_no; } void setName() { cout <<"\nEnter the name of the student: "; cin >>cName; } int getRegno() { return iReg_no; } char *getName() { return cName; } }; int main() { ofstream Sfil("studfile.dat"); char ch; student svar; cout <<"Want to enter more records\n"; cin >>ch; while (1) { if (ch == 'y') { if (ch =='n') break; svar.setRegno(); svar.setName(); Sfil.write((char*)&svar, sizeof(student)); cout <<"Want to enter more records: "; cin >>ch; } if (ch == 'n') break; } Sfil.close(); cout <<"\nDo you want to view the contents of the file (y/n)? "; cin >>ch; if (ch =='y') { ifstream Sfil("studfile.dat"); Sfil.read((char *)&svar, sizeof(student)); while(Sfil) { cout <<"\n Registration Number is: " <