Advertisement
Lucky_Dummy

Untitled

Dec 23rd, 2021
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include <fstream>
  4.  
  5. typedef char byte;
  6.  
  7. class IInputStream {
  8. public:
  9.         virtual bool Read(byte& value) = 0;
  10. };
  11.  
  12. class IOutputStream {
  13. public:
  14.         virtual void Write(byte value) = 0;
  15. };
  16.  
  17. class CInputStream : public IInputStream {
  18. public:
  19.     explicit CInputStream(const std::string& fName) {
  20.         fin.open(fName);
  21.     }
  22.     ~CInputStream() {
  23.         fin.close();
  24.     }
  25.     bool Read(byte& value) override;
  26.  
  27. private:
  28.     std::ifstream fin;
  29. };
  30.  
  31. bool CInputStream::Read(byte &value) {
  32.     if (fin >> value) {
  33.         return true;
  34.     }
  35.     return false;
  36. }
  37.  
  38. class COutputStream : public IOutputStream {
  39. public:
  40.     explicit COutputStream(const std::string& fName) {
  41.         fout.open(fName);
  42.     }
  43.     ~COutputStream() {
  44.         fout.close();
  45.     }
  46.     void Write(byte value) override;
  47. private:
  48.     std::ofstream fout;
  49. };
  50.  
  51. void COutputStream::Write(byte value) {
  52.     fout << value;
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement