SOS!关于数据读写中字节的问题
我先把数组中的数(注意是int类型的)写入到文件中,再把这个文件中的内容写入到数组中,可是本来我有5个数,从文件中读出来之后成7个数了,字节问题怎么处理,比如1和1000应该占用相同的字节,长度应该是相同的,用我以下的方法做了之后,长度是不同的,比如1的长度就是1,1000的长度就是4了,从文件里面读出的时候就是一个一个的读出的,1000就成了1、0、0、0了,请问大侠怎么处理这样的问题,谢谢各位了!
以下是我的代码:void __fastcall TForm1::Button1Click(TObject *Sender)
{
//将数组中的内容写入文件
int array[5]={10,2,35,4,5};
int i;
int iFileHandle;
int iLength;
iFileHandle=FileOpen("f:\\xcl\\课题模块\\text1.txt",fmOpenWrite);
for (i=0;i<5;i++)
{
AnsiString Test = IntToStr(array[i]);
int len=Test.Length();
FileWrite(iFileHandle, Test.c_str(), len);
}
FileClose(iFileHandle);
}
void __fastcall TForm1::Button2Click(TObject *Sender)
{
//从文件里面读到数组里
int iFileHandle,iBytesRead,iFileLength;
int i,Y=10,del_y=15;
char *pszBuffer;
iFileHandle=FileOpen("f:\\xcl\\课题模块\\text1.txt",fmOpenRead); //打开文件
iFileLength=FileSeek(iFileHandle,0,2); //检查文件长度
pszBuffer=new char[iFileLength+1]; //设置虚拟空间为文件长度+1
FileSeek(iFileHandle,0,0);
iBytesRead=FileRead(iFileHandle,pszBuffer,iFileLength);
FileClose(iFileHandle);
for(i=0;i<iBytesRead;i++)
{
Canvas->TextOut(10,Y+del_y,StrToInt(pszBuffer[i]));
Y=Y+del_y;
}
delete [] pszBuffer;
}