Hej udviklere.
Jeg har lavet et program der gemmer char data i en binary fil, og så åbner den filen igen for at se dataene, men jeg får bare en underlig tekst tilbage. Håber i kan hjælpe.
#include <fstream>
#include <Windows.h>
#include <stdio.h>
#include <iostream>
using namespace std;
struct sUser
{
char Username[256];
char Password[256];
char Email[256];
int Point;
};
int main()
{
sUser user;
sUser read_user;
char tmp[256];
cout << "Skriv Username: ";
cin.getline(user.Username, 256);
cout << endl << user.Username << endl;
cout << "Skriv Password: ";
cin >> user.Password;
cout << endl << user.Password << endl;
cout << "Skriv Email: ";
cin >> user.Email;
cout << endl << user.Email << endl;
cout << "Skriv Point: ";
cin >> user.Point;
cout << endl << user.Point << endl;
MessageBox(NULL, LPSTR(user.Username), "Hej", MB_ICONINFORMATION);
sprintf(tmp, "%s.dat", (char*)user.Username);
fstream file(tmp, ios::out | ios::binary);
file.write(reinterpret_cast<char*>(&user), sizeof(sUser));
file.close();
fstream read_file(tmp, ios::in | ios::binary);
file.read(reinterpret_cast<char*>(&read_user), sizeof(sUser));
file.close();
MessageBox(NULL, LPSTR(read_user.Username), "Hej", MB_ICONINFORMATION);
cout << "Finish" << endl;
system("PAUSE");
}