spo/ass2/fileDevice.cpp

23 lines
545 B
C++

#include <string>
#include <fstream>
#include "fileDevice.h"
#include <stdexcept>
fileDevice::fileDevice(std::string& filename): file(filename, std::ios::in | std::ios::out | std::ios::binary) {
if (!file.is_open()) {
throw std::runtime_error("Datoteke ni mogoče odpreti: " + filename);
}
}
uint8_t fileDevice::read() {
int c = file.get();
if (c == EOF) {
return 0;
}
return static_cast<uint8_t>(c);
}
void fileDevice::write(uint8_t val) {
file.put(static_cast<char>(val));
file.flush();
}