有一个地方不明白,请高手相助
#include<iostream.h>#include<fstream.h>
#include<string.h>
#include<stdlib.h>
struct status{
char name[40];
float balance;
unsigned long account_number;
};
void main(){
struct status acc;
strcpy(acc.name,"lars klander");
acc.balance=1234.56;
acc.account_number=98765432;
ofstream outbal("balance.asc",ios::out|ios::binary);
if(!outbal) {
cout<<"canot open output file"<<endl;exit(1);}
outbal.write((unsigned char *)&acc,sizeof(struct status));
outbal.close();
ifstream inbal("balance.asc",ios::in|ios::binary);
if(!inbal){
cout<<"canot open file"<<endl;exit(1);
}
inbal.read((unsigned char *)&acc,sizeof(struct status));
cout<<acc.name<<endl;
cout<<"account number: "<<acc.account_number<<endl;
cout.precision(2);
cout.setf(ios::fixed);
cout<<"balanced: $ "<<acc.balance<<endl;
inbal.close();
}
请问为什么在acc前加“&”而不是“*”,加“&”的作用是什么,我试过加“*”程序报错
[[it] 本帖最后由 hank_wh 于 2008-7-21 20:29 编辑 [/it]]