#include <fstream>
#include <iostream>
#include <iosfwd>

const long long max = 800000000LL;

int main()
{
    std::fstream file("test.file",
        std::ios_base::in     | std::ios_base::out |
        std::ios_base::binary | std::ios_base::trunc);

    if (!file)
        std::cout << "Could not open test.file\n";

    for (long long i = 0; i < max; ++i)
        file.write(reinterpret_cast<char*>(&i), sizeof(i));

    long long x;
    file.seekg((max - 1) * sizeof(x), std::ios_base::beg);
    file.read(reinterpret_cast<char*>(&x), sizeof(x));
    if (x != (max - 1))
        std::cout << "seekg with offset failed to position the file correctly\n";

    std::fstream::pos_type pos((max - 2) * sizeof(x));
    file.seekg(pos);
    file.read(reinterpret_cast<char*>(&x), sizeof(x));
    if (x != (max - 2))
        std::cout << "seekg with pos_type failed to position the file correctly\n";

    return 0;
}

