Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cstdlib>
- #include <vector>
- #include <sstream>
- std::istringstream read(std::string filename)
- {
- using namespace std;
- ifstream fin(filename, fstream::binary);
- vector<uint8_t> res;
- const int SIZE_OF_BUFFER = 128;
- try
- {
- for (char temp[SIZE_OF_BUFFER]; fin; )
- {
- fin.read(temp, SIZE_OF_BUFFER);
- res.insert(res.end(), temp, temp + fin.gcount());
- cout << fin.gcount() << endl;
- if (fin.gcount() != SIZE_OF_BUFFER)
- break;
- }
- }
- catch (exception e)
- {
- cout << e.what();
- }
- fin.close();
- istringstream ss(string((char*)res.data()), istringstream::binary);
- return move(ss);
- }
- int main(void)
- {
- auto ss = read("input.txt");
- short a = 0, b = 0;
- char c = 0;
- for (; ss; )
- {
- ss.read((char*)&a, sizeof(a));
- ss.read((char*)&b, sizeof(b));
- ss.read((char*)&c, sizeof(c));
- std::cout << a << " " << b << " " << c << std::endl;
- }
- system("pause");
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement