无法使CFile追加到文件 [英] can't get CFile to append to a file

查看:76
本文介绍了无法使CFile追加到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码

Hi, here is my code

CFile wspLogFile;

if(m_logFileExists)
{
	wspLogFile.Open(m_logFilePath, CFile::modeCreate | CFile::modeNoTruncate | CFile::modeWrite);
	wspLogFile.SeekToEnd();
	wspLogFile.Write(buffer, bufferSize);
	wspLogFile.Flush();
}
else
{
	m_logFilePath = m_workspaceFolderPath + _T("\\") + m_name +_T(".log");
	wspLogFile.Open(m_logFilePath, CFile::modeCreate | CFile::modeWrite);
	wspLogFile.Write(buffer, bufferSize);
	wspLogFile.Flush();
	m_logFileExists = true;			
}



else {}应该创建一个新文件,并将缓冲区的内容写入该文件中. if(m_logFileExists){}应该将缓冲区追加到在else {}中创建的文件.但是,这不会发生,文件也不会完全更新,并且仍然包含在else {}中写入该文件的文本.请有人告诉我我做错了什么.我真的已经用谷歌搜索了,没有发现任何有用的东西.



The else{} is supposed to create a new file and write the contents of buffer to it, which it does. The if(m_logFileExists){} is supposed to append buffer to the file that was created in the else{}. However, this does not happen, the file is not updated atall, and still contains the text that was written to it in the else{}. Please could someon etell me what i''m doing wrong. I really have googled this and not found anything that helps. Should I just scrap this and use ofstream?

推荐答案

否则,这是我看到的唯一设置文件名m_lofFilePath的地方.是在其他地方设置的还是问题的根源?
The else case is the only place I see that sets the file name m_lofFilePath. Is it set somewhere else or is that the source of the problem?


这篇关于无法使CFile追加到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆