Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstdlib>
  4. #include <vector>
  5. #include <sstream>
  6.  
  7. std::istringstream read(std::string filename)
  8. {
  9. using namespace std;
  10.  
  11. ifstream fin(filename, fstream::binary);
  12.  
  13.  
  14. vector<uint8_t> res;
  15.  
  16. const int SIZE_OF_BUFFER = 128;
  17. try
  18. {
  19. for (char temp[SIZE_OF_BUFFER]; fin; )
  20. {
  21. fin.read(temp, SIZE_OF_BUFFER);
  22.  
  23. res.insert(res.end(), temp, temp + fin.gcount());
  24.  
  25. cout << fin.gcount() << endl;
  26.  
  27. if (fin.gcount() != SIZE_OF_BUFFER)
  28. break;
  29. }
  30. }
  31. catch (exception e)
  32. {
  33. cout << e.what();
  34. }
  35.  
  36. fin.close();
  37.  
  38. istringstream ss(string((char*)res.data()), istringstream::binary);
  39. return move(ss);
  40. }
  41.  
  42. int main(void)
  43. {
  44. auto ss = read("input.txt");
  45.  
  46. short a = 0, b = 0;
  47. char c = 0;
  48.  
  49. for (; ss; )
  50. {
  51. ss.read((char*)&a, sizeof(a));
  52. ss.read((char*)&b, sizeof(b));
  53. ss.read((char*)&c, sizeof(c));
  54. std::cout << a << " " << b << " " << c << std::endl;
  55. }
  56.  
  57. system("pause");
  58. return EXIT_SUCCESS;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement