写数据(现在写的整数)
CFile cf;
cf.Open("C://date.txt",C File::modeCreate | CFile::modeNoTruncate | CFile::modeWrite | CFile::modeRead);
int temp[32];
for(inr I=0;I<32;I++)
{
temp[I]=I+2;
cf.SeekToEnd();
cf.WriteHuge(&temp[i],sizeof(int));
}
2、
读数据(现在读的整数)
VC中整数占4个字节,要从第2 3 4…个开始读,要Seek(8 12 16…)
CFile cf;
int szName,szDate[32];
if(cf.Open(_T("C://date.txt"),CFile::modeRead))
{
cf.Seek(turn2*32*sizeof(int),CFile::begin);
for(i=0;i< 32;i++ ) //cf.GetLength()
{
cf.Read(&szName,sizeof(int));
szDate[i]=szName;
}
cf.Close();
}
3、读写String类型的数据
/*
//读
CString sText;
CStdioFile file;
CClientDC dc(this);
if(file.Open("C:/Recc00.txt",CFile::modeRead |
CFile::typeText
))
{
long x,y;
x=0;
y=0;
TEXTMETRIC textMetric;
dc.GetTextMetrics(&textMetric);
while(file.ReadString(sText))
{
pDC->TextOut(x,y,sText);
y += textMetric.tmHeight;
}
file.Close();
}
*/
/*
//读
CFile arFile;
CString strTemp;
CClientDC dc(this);
TEXTMETRIC textMetric;
dc.GetTextMetrics(&textMetric);
CArchive ar(&arFile,CArchive::load);
int x=0,y=0;
if( !arFile.Open("C:/Recc00.txt",CFile::modeRead) )
{
pDC->TextOut(0,0,"Cuo Wu");
return;
}
while(ar.ReadString(strTemp))
{
pDC->TextOut(x,y,strTemp);
y += textMetric.tmHeight;
}
ar.Close();
arFile.Close();
*/
/*
//写
CStdioFile file;
char buf[]="text string32456788888,,88/n99999999,,9944444/n66666655555";
if(file.Open("C:/Recc00.txt",CFile::modeWrite |
CFile::typeText
))
{
file.WriteString(buf);
file.Close();
}
*/
/*
//写
CFile arFile;
arFile.Open("C:/Recc00.txt",CFile::modeCreate|CFile::modeNoTruncate|CFile::modeWrite);
CArchive ar(&arFile,CArchive::store);
BYTE byTemp = 1;
long lTemp = 100;
double dTemp=3.1415926;
CString StrTemp = "My String!";
ar<<byTemp<<lTemp;
ar<<dTemp;
ar<<StrTemp;
ar.Close();
arFile.Close();
*/