Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <fstream>
- typedef char byte;
- class IInputStream {
- public:
- virtual bool Read(byte& value) = 0;
- };
- class IOutputStream {
- public:
- virtual void Write(byte value) = 0;
- };
- class CInputStream : public IInputStream {
- public:
- explicit CInputStream(const std::string& fName) {
- fin.open(fName);
- }
- ~CInputStream() {
- fin.close();
- }
- bool Read(byte& value) override;
- private:
- std::ifstream fin;
- };
- bool CInputStream::Read(byte &value) {
- if (fin >> value) {
- return true;
- }
- return false;
- }
- class COutputStream : public IOutputStream {
- public:
- explicit COutputStream(const std::string& fName) {
- fout.open(fName);
- }
- ~COutputStream() {
- fout.close();
- }
- void Write(byte value) override;
- private:
- std::ofstream fout;
- };
- void COutputStream::Write(byte value) {
- fout << value;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement