Skip to content

Instantly share code, notes, and snippets.

@scooby
Created February 8, 2009 05:31
Show Gist options
  • Save scooby/60208 to your computer and use it in GitHub Desktop.
Save scooby/60208 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <fstream>
using namespace std;
int main(void) {
fstream foo1;
foo1.open("seek.bin", ios_base::in | ios_base::out | ios_base::binary | ios_base::trunc);
int i;
for(i = -100; i < 99; i ++) {
foo1.write((char*) &i, sizeof(int));
}
foo1.flush();
istream foo2(foo1.rdbuf());
foo1.seekg(0, ios_base::beg);
foo2.seekg(100 * sizeof(int), ios_base::beg);
for(i = 0; i < 50; i++) {
int j, k;
foo1.read((char*) &j, sizeof(int));
foo2.read((char*) &k, sizeof(int));
cout << j << ", " << k << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment