下面这段代码编译执行都可以通过,没有报错,但是就是默认路径下1.eml文件里没有写进任何内容。
请问是什么原因?有关代码如下:
CFile emlfile;
CFileException e;
char* pFileName = "1.eml";
if( !emlfile.Open( pFileName, CFile::modeCreate | CFile::modeWrite, &e ) )
{
#ifdef _DEBUG
afxDump << "File could not be opened " << e.m_cause << "\n";
#endif
}
emlfile.Write(response_buf, RESPONSE_BUFFER_SIZE );
emlfile.Close();1.eml文件是否需要事先新建?还是由程序自动生成?(PS:这两种情况我都试了,事先建好1.eml文件,程序运行后,1.eml里没有任何内容;如没有建立,程序运行后也没有自动生成1.eml文件)本人VC菜鸟一只,请多多指教!
请问是什么原因?有关代码如下:
CFile emlfile;
CFileException e;
char* pFileName = "1.eml";
if( !emlfile.Open( pFileName, CFile::modeCreate | CFile::modeWrite, &e ) )
{
#ifdef _DEBUG
afxDump << "File could not be opened " << e.m_cause << "\n";
#endif
}
emlfile.Write(response_buf, RESPONSE_BUFFER_SIZE );
emlfile.Close();1.eml文件是否需要事先新建?还是由程序自动生成?(PS:这两种情况我都试了,事先建好1.eml文件,程序运行后,1.eml里没有任何内容;如没有建立,程序运行后也没有自动生成1.eml文件)本人VC菜鸟一只,请多多指教!
有CFile::modeCreate就不需要实现创建好文件了。
char *yourbuf;//你的缓冲指针。
FILE *pthefile;
pthefile = fopen("c:\\yourfile.txt", a+);
if(pthefile)
{
fwrite(yourbuf,strlen(yourbuf),1,pthefile);
fclose(pthefile);
}