首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

如何吧CString写到一个文件里呢

2012-01-29 
怎么吧CString写到一个文件里呢如何把CString写到一个文件里呢.比如说abc.htm,如果没有则建立该文件[解决

怎么吧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);

热点排行