ok so im on the 2nd Semester on my unversity have done c and doing c++ now doing the project in DevC.
Currently im making a program that will do the charging processes of a shop while having and editing the database.
Tried writing and reading a full struct but dosent work so i went down writing 2 int numbers and reading them but this also dosent work while getting random number when reading even though if i write txt the numbers seem ok.
//write and read are different fucntion only 1 is called .
//file creation code
int AccountNumber=0;
ofstream FileCreator("Database.dat",ios::binary);
FileCreator<<AccountNumber;
AccountNumber=1;
FileCreator<<AccountNumber;
and
//reading code
int AccountNumber=0;
ifstream FileCreator("Database.dat",ios::binary);
FileCreator.seekg(0,ios::beg);
FileCreator.read(reinterpret_cast<char*>(&AccountNumber), sizeof(AccountNumber));
cout<<AccountNumber<<endl;
FileCreator.read(reinterpret_cast<char*>(&AccountNumber), sizeof(AccountNumber));
cout<<AccountNumber<<endl;
I expect 0 and 1 at the output but get 12592 and 12592.
std::ostream::write, notoperator<<. So,FileCreator<<AccountNumbershould be replaced byFileCreator.write((char *) &AccountNumber, sizeof(AccountNumber)).