Challenge: Print backwards with seekg((ios::off_type)value, ios::cur)

#include <iostream>
#include <fstream>
using namespace std;

int main(){
int i;

fstream file(“output.bin”,ios::in|ios::binary);

file.seekg((ios::off_type)0, ios::end); // goes to the end again

file.seekg((ios::off_type)(-4), ios::cur);
file.read((char*)&i, sizeof(i));
cout<<i<<“, “;

int j = 1;
int k = file.tellg();
while(j<k/sizeof(int)){
file.seekg((ios::off_type) (-8), ios::cur);
file.read((char*)&i, sizeof(i));
cout<<i<<“, “;
j++;
}
return 0;
}

Advertisements