#include <cstdlib>
#include <iostream>
#include<fstream>
#include<cstring>
using namespace std;
int main(int argc, char *argv[]){
struct status{
char name[80];
double balance;
unsigned long account_num;
};
struct status acc;
strcpy(acc.name,"Harry");
acc.balance=1123.23;
acc.account_num=23298208;
//write data
ofstream outbal
("balance",ios::out|ios::binary);
if(!outbal){
cout<<"Cannot open file.\n";
return 1;
}
outbal.write((char*)
&acc,sizeof(struct status));
outbal.close();
ifstream inbal
("balance",ios::in|ios::binary);
if(!inbal){
cout<<"Cannot open file.\n";
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;
inbal.close();
system("PAUSE");
return EXIT_SUCCESS;
}
0 komentar:
Posting Komentar