// filetest-random.cpp #include #include #include const int LINESIZE=256; using namespace std; struct Record{ char name[128]; int age; }; main(){ fstream rwFile; rwFile.open("datafile", ios::in | ios::out); if (rwFile.fail()){ cerr << "Error opening datafile" << endl; exit(1); } Record person; strcpy(person.name, "Steve J. Hodges"); person.age = 18; rwFile.seekp(0); rwFile.write( reinterpret_cast( &person), sizeof(person) ); // int a[10]; // cout << sizeof(a) / sizeof(int); Record inPerson; rwFile.seekg(0); rwFile.read( reinterpret_cast( &inPerson), sizeof(Record) ); cout << inPerson.name << endl; rwFile.close(); }