Popravil fileDevice.cpp tako da dejansko naredi datoteke, če še ne obstajajo

This commit is contained in:
Timon 2025-12-01 13:37:24 +01:00
parent 8222f8dd0a
commit 74cc571eef
270 changed files with 104 additions and 74 deletions

View file

@ -0,0 +1,31 @@
#include "../headers/fileDevice.h"
#include <stdexcept>
fileDevice::fileDevice(const std::string& filename) {
file.open(filename, std::ios::in | std::ios::out | std::ios::binary);
if (!file.is_open()) {
std::ofstream create(filename, std::ios::binary);
create.close();
file.open(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();
}
bool fileDevice::test() {return true;}