Sunday, December 6, 2009

Printing a file backwards

int main(){
Student S;
fstream fback("std.bin",ios::in| ios::binary);
fback.seekg(-(sizeof(Student)), ios::end);
while (!fback.read((char *)&S, sizeof(Student)).fail()) {
cout << S << endl;
fback.seekg(-2 * (sizeof(Student)), ios::cur);
}
return 0;
}

No comments:

Post a Comment