怎么吧CString写到一个文件里呢
如何把CString写到一个文件里呢.比如说abc.htm,如果没有则建立该文件
[解决办法]
CFile hfile( "abc.htm ",CFile::modeCreate|CFile::modeWrite);
CArchive ar(&hfile,CArchive::load);
CString str;
ar < <str;
ar.Flush();
ar.Close;
hfile.Close();
[解决办法]
CFile cf;
cf.Open( "C:\\abc.htm ",CFile::modeCreate|CFile::modeReadWrite);
cf.Write(str,str.GetLength());//CStrint str;
cf.Close();
[解决办法]
int WriteStringToTxtFile_c(char *msg, char *fn)
{
int retCode = 0;
FILE *fp;
fp=fopen(fn, "wt ");
if (fp != NULL)
{
fprintf(fp, "%s ", msg);
fclose(fp);
retCode = 1;
}
return retCode;
}
[解决办法]
c里就用fopen,open,c++里用iostream MFC里用CFile,及其继承类CStdioFile
上面的都写了个遍.
[解决办法]
还有一种
HFILE hf;
OFSTRUCT ofs;
hf = OpenFile( "abc.htm ",&ofs,OF_CREATE|OF_WRITE);
_lwrite(hf,str,str.GetLength());
_lclose(hf);