怎样从二进制文件中读出double类型数据??
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
struct
{
double salary;
char name[23];
}employee1;
employee1.salary=8000;
strcpy(employee1.name,"L Zheng");
ofstream outfile("payroll",ios_base::binary);
outfile.write((char *) &employee1,sizeof(employee1));
outfile.close();
char ch;
ifstream tfile("payroll",ios_base::binary);
if(tfile)
{
//cout<<tfile.tellg()<<endl;
tfile.seekg(8);
//cout<<tfile.tellg()<<endl;
while(tfile.good())
{
//double b;
// cout<<"tellg():"<<tfile.tellg()<<endl;
//tfile.read((char*) &b,sizeof(double));
//cout<<b<<endl;
tfile.get(ch);
if(!ch) break;
cout<<ch;
}
}
else
{
cout<<"ERROR:Cannot open file 'payroll'."<<endl;
}
tfile.close();
return 0;
}
怎样从二进制文件中读出salary(double类型的)的值呢?