// Project RandomAccess // File main2.cpp #include #include using namespace std; #include "person.h" Person read_input(istream &, int); int main() { Person p; int index; ifstream fin("person.txt", ios::in | ios::binary); cin >> index; while(0 <= index && index <= 6) { p = read_input(fin, index); cout << p.name << " " << p.gender << " " << p.age << endl; cin >> index; } return EXIT_SUCCESS; } Person read_input(istream &f, int index) { Person p; f.seekg(index * sizeof(Person), ios::beg); f.read(reinterpret_cast(&p), sizeof(Person)); return p; } // Sample Input and Output: // 3 // Mary F 36 // 5 // Jane F 27 // 0 // Tom M 23 // 1 // Bill M 34 // -1