gpt4 book ai didi

c++ - CFile Copy 方法修复文件访问被拒绝问题

转载 作者:行者123 更新时间:2023-11-28 08:05:52 24 4
gpt4 key购买 nike

我的应用遇到了 ramdon 错误。生成新文件且大小为 0K 时,txt 文件访问被拒绝。

我只想复制现有文件并在关闭当前文件后重命名它。

谁能给我一个复制文件的方法?谢谢。

我的代码片段如下。

ofstream    m_LogFile;

CFile logcfile;

if(dwLength > 1024*1024*10 )
{
string fileDate = status.m_mtime.Format("%Y%m%d%H%M%S");
string modulePath = Util::GetModulePath();
string fileNewName(modulePath);
fileNewName += "mytextlog" + fileDate + ".txt";
m_LogFile.close();
// I want to insert CFile copy method before rename it.
logcfile.Rename(m_sLogFileName.c_str(), fileNewName.c_str());
m_LogFile.open(m_sLogFileName.c_str(), ios::out | ios::app);
_findfile(modulePath.c_str());
}

我假设我的应用程序错误是由上面的代码引起的。

最佳答案

CFile 没有复制文件的方法。

使用::CopyFile() 函数可以简单地复制文件,而无需打开和关闭文件。

关于c++ - CFile Copy 方法修复文件访问被拒绝问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10308724/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com