#include #include template typ1 readFromStream(std::ifstream &stream, char *dest) { if (stream.is_open()) { stream.read(dest, sizeof(char[1024])); typ1 *ptr = reinterpret_cast(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(stream, dest); printf("I read something!\n%X\n", header); for (int i = 0; i < 1024; i++) { std::cout << dest[i] << std::endl; } long *test = reinterpret_cast(dest); printf("Verification Code: %X\n", *test); char *fuckery = (char *)test; printf("Fuckery: %X\n", fuckery); // Name char *byte20 = &dest[20]; std::cout << "Name: "; for (int i = 0; i < 16; i++) { std::cout << byte20[i]; } std::cout << std::endl; char* byte36 = &dest[36]; std::cout << "Status: " << (((int)(*((bool *)byte36)))%8)/4 << std::endl; // geh zu Byte 36, lies genau 1 byte (da sizeOf(bool) = 1), interpretier es als int, berechner mod 8 -> wegwerfen der linken Bits, /4 -> wegwerfen der rechten beiden Bits -> Tada, nur das 3. Bit von Rechts bleibt übrig // Klasse bool *byte40 = (bool*) &dest[40]; std::cout << "Klasse: " << byte40[0] << std::endl; // 2 -> Necromancer } catch (const std::exception &e) { std::cout << e.what() << std::endl; } }