Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdint.h>
- #include <cassert>
- #include <fstream>
- #include <iostream>
- #include <vector>
- //! Main program that demonstrates large file handling
- int
- main
- ( int const argc
- , char const * const * const argv
- )
- {
- std::ofstream ofs("bigfile.bin", std::ios::binary);
- std::cerr << sizeof(std::streamoff) << std::endl;
- std::cerr << sizeof(std::ios::pos_type) << std::endl;
- std::cerr << sizeof(std::ios::off_type) << std::endl;
- // 4mb test buffer
- std::vector<uint32_t> buffer(1024 * 1024);
- size_t const bufbytes(sizeof(buffer[0]) * buffer.size());
- std::generate(buffer.begin(), buffer.end(), std::rand);
- uint64_t totalbytes(0);
- uint64_t const desiredbytes(3ULL * 1024ULL * 1024ULL * 1024ULL);
- while (totalbytes < desiredbytes)
- {
- ofs.write((char const *)&buffer[0], bufbytes);
- totalbytes += bufbytes;
- }
- ofs.close();
- std::ifstream ifs("bigfile.bin", std::ios::binary);
- ifs.seekg(0, std::ios::end);
- std::ios::streampos const fsize(ifs.tellg());
- std::cout << "seek from end: " << fsize << std::endl;
- ifs.seekg(0);
- ifs.seekg(fsize);
- std::cout << "seek to end: " << ifs.tellg() << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment