各位大侠,小弟我想做一个函数:
CString getFileContent(CString fileName){....}
就是输入一个文件名,然后将文件的内容读出来,写到一个字符串中,然后将此字符串返回。
急!!谢谢!!
CFile file;
CString str="";
char *ch;
file.Open(filename,CFile::modeRead);
int filelenth=file.GetLength();
ch=new char[filelenth];
file.Read(ch,filelenth);
for(int i=0;i<filelenth;i++) str+=ch[i]
file.Close();
return str;
CString str;
CFile file;
file.Open("test",CFile::modeRead);
int n = file.GetLength();
file.Read((void *)(LPCTSTR)str,n);
AfxMessageBox(str);
file.Close();