S3_Cpp/Aufg9/DiabloByteReader.cpp
2024-12-11 23:36:38 +01:00

37 lines
924 B
C++

#include <fstream>
#include <iostream>
template <typename typ1>
typ1 readFromStream(std::ifstream &stream, char *dest) {
if (stream.is_open()) {
stream.read(dest, sizeof(char[1024]));
typ1 *ptr = reinterpret_cast<typ1 *>(dest);
return std::move(*ptr);
}
else {
std::runtime_error("Could not read from File!");
}
}
void Aufg9Main() {
char *dest = new char[1024];
try {
std::string fileName = "../Aufg9/IO-Files/charakter.d2s";
std::ifstream stream(fileName);
auto header = readFromStream<long>(stream, dest);
printf("I read something!\n%X\n", header);
for (int i = 0; i < 16; i++) {
std::cout << dest[i] << std::endl;
}
long *test = reinterpret_cast<long *>(dest);
printf("Test: %X\n", *test);
} catch (const std::exception &e) {
std::cout << e.what() << std::endl;
}
}