c中的写法:
Code
/*read File*/
char *txt = NULL;
long txtlen;
//seek to file end to calculate file length
fseek(fp,0,SEEK_END);
txtlen=ftell(fp);
//rewind to file start
rewind(fp);
//read from file
txt = new char[txtlen + 1];
if (txt != NULL)
{
fread(txt,sizeof(char),txtlen,fp);
txt[txtlen]='\0';
fv.setData(txt);
}
//close file and destroy temp array
fclose(fp);
if(txt!=NULL)
{
delete []txt;
txt = NULL;
}
c++的写法:
Code
/*read File*/
ifstream in(filesrc);
if(in.fail())
{
printf("open file failed!\n");
}
else
{
string strtmp;
while (getline(in,strtmp))
{
fv.getData()+=strtmp;
fv.getData()+='\n';
}
in.close();
}
posted @
2008-08-07 14:14
fishert
阅读(
1335)
评论()
编辑
收藏
举报