无法使用 ofstream 写入 Windows 7 中的临时文件夹
Can't write to temp folder in Windows 7 using ofstream
当我使用QT时,我使用QT-Way获取Windows Temp文件夹。这有效,但是看起来我无法写入此文件夹。
这是代码:
const QStringList defaultFolders = QStandardPaths::standardLocations(QStandardPaths::TempLocation);
const QString tempFolder = defaultFolders.first();
const QString fileName = tempFolder + "/testFile.txt";
ofstream file(fileName.toLocal8Bit(), fstream::out);
const bool ok = file.is_open();
const QString msg = ok ? "Success" : "Failure";
QMessageBox::warning(this, fileName, msg);
我到目前为止尝试了
- 使用" \"的硬编码路径而不是"/"
- 使用.tostDstring()。c_str()而不是" .tolocal8bit()
注释
- 路径中有一个突出的字符。
- Windows用户是管理员
- 我可以在临时文件夹中手动创建/删除文件,但是编译的应用程序不能。
- 我正在虚拟机中运行Windows 7
- 如果我使用旧的C函数(Fopen/fwrite/fclose) ,它的工作正常
有人知道出了什么问题吗?
也许使用toStdWString()
代替toLocal8Bit()
会更好吗?
std::filesystem::path filePath(fileName.toStdWString());
std::ofstream file(filePath);
相关文章:
- 在 Windows 上,是否可以让 dll 在不使用 PATH 环境变量的情况下在另一个文件夹中查找依赖项?
- vcruntime.h 从 Windows 包含文件夹中丢失?
- 如何从Windows控制台调用.exe(C++)以在不同的目录(或任何目录)中创建文件夹?
- Windows C++:文件夹移动访问被拒绝错误
- 如何使用Windows API C++更改已创建的文件夹/目录安全权限
- Windows 后台服务(系统配置文件)无法使用 C++ 访问 win 10 上的用户 appData 文件夹?
- 确实可以提高directory_iterator在Windows上按字母顺序访问文件和文件夹
- 如何在 Windows 中立即刷新文件夹图标
- 使用内置的Windows方法获取文件夹的内容
- 我可以在C 中的Windows中读取一个文件,而无需锁定包含文件的文件夹
- 从Windows上的系统工作的服务中获取用户文档文件夹.C++
- Windows 资源管理器打开文件夹还原
- 无法使用 ofstream 写入 Windows 7 中的临时文件夹
- 如何在QT中获取Windows默认文件夹的本地名称
- Qfiledialog:文件夹名称在Windows下方出现两次
- 打开Windows Explorer中的公共文档文件夹
- 将Windows上32位和64位的Boost构建到同一文件夹中
- Windows SDK 8:关于安装位置,文件夹命名法和Windowssdkdir_old Env变量的混乱
- 在C++中重命名Windows文件夹
- 移动文件夹Windows c++:适用于Vista及以上版本,不包括XP