#include <cstdlib>
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
struct status{
char name[80];
double balance;
unsigned long account_num;
};
int main(int argc, char *argv[])
{
status acc;
strcpy(acc.name,"Star white");
acc.balance=1123.23;
acc.account_num=1234568;
ofstream outbal("balance",ios::out|ios::binary);
if(!outbal){
cout<<"tidak dapat buka file"<<endl;
return 1;
}
outbal.write((char*)&acc,sizeof(struct status));
outbal.close();
ifstream inbal("balance",ios::in|ios::binary);
if(!inbal){
cout<<"tidak dapat buka file"<<endl;
return 1;
}
inbal.read((char*)&acc,sizeof(struct status));
cout<<acc.name<<endl;
cout<<"account# "<<acc.account_num;
cout.precision(2);
cout.setf(ios::fixed);
cout<<endl<<"balance$ "<<acc.balance<<endl;
inbal.close();
system("PAUSE");
return EXIT_SUCCESS;
}
Tidak ada komentar:
Posting Komentar