一段C++文件读取的代码问题

来源:百度知道 编辑:UC知道 时间:2024/05/15 06:40:12
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#include <string.h>

class InorOut
{ public:
double In;
double Out;
char Date[9];
void Display();
};

void InorOut::Display()
{ cout<<Date<<"\t\t"<<In<<"\t\t";
cout<<Out<<"\t\t"<<In - Out;
cout<<"\t\t";
}

void Show(InorOut *CurUsrInc)
{ InorOut *AllInc;
fstream f("0000.sav",ios::binary|ios::in|ios::out);
if(!f)
{cerr<<"文件不能打开"<<endl;
return;
}
f.seekg(0,ios::end);
long posEnd=f.tellg();
f.seekg(0,ios::beg);
do
{f.read((char*)&AllInc,sizeof(InorOut));
}while(f.tellg()!=posEnd);
}

void main()
{ InorOut *CurUsrInc;
CurUsrInc = (InorOut*)malloc(sizeo

#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#include <string.h>

class InorOut
{
public:
double In;
double Out;
char Date[9];
void Display();
};

void InorOut::Display()
{
cout<<Date<<"\t\t"<<In<<"\t\t";
cout<<Out<<"\t\t"<<In - Out;
cout<<"\t\t";
}

void Show(InorOut *CurUsrInc)
{
InorOut *AllInc = new InorOut; //new instance
fstream f("0000.sav",ios::binary|ios::in); /////////////////////open method
if(!f)
{
cerr<<"文件不能打开"<<endl;
return;
}
f.seekg(0,ios::end);
long posEnd=f.tellg();
f.seekg(0,ios::beg);
do
{
f.read((char*)AllInc,sizeof(InorOut)); //no &
}while(f.t