c++ - 为什么列出目录中所有文件的代码会崩溃?
问题描述
它不会立即崩溃,for
循环列出了一些文件路径,然后我得到了这个异常:
testpath.exe 中 0x76F05608 处未处理的异常:Microsoft C++ 异常:内存位置 0x0044F8A8 处的 std::filesystem::filesystem_error。
CSIDL_DESKTOP
但是,如果它不是,它不会崩溃CSIDL_PROGRAM_FILESX86
。
#include <iostream>
#include <filesystem>
#include <shlobj.h>
#pragma comment(lib, "shell32.lib")
namespace fs = std::filesystem;
int main()
{
CHAR programx86[MAX_PATH];
HRESULT result = SHGetFolderPath(NULL, CSIDL_PROGRAM_FILESX86, NULL, SHGFP_TYPE_CURRENT, programx86);
for (auto& p : fs::recursive_directory_iterator(programx86))
{
std::cout << p.path().u8string() << std::endl;
}
}
解决方案
推荐阅读
- flutter - How to build a dynamic list view with 3 items in row in flutter
- javascript - 局部函数完成后全局变量失去其值
- android - 用于 tablayout 和查看寻呼机的 Espresso 相对如何执行点击和滑动(kotlin)
- php - SQLSTATE[28000] [1045] 用户“root”的访问被拒绝
- java - 较新操作系统上的文件选择器 - 未找到文件
- java - 如何从我自己的应用程序运行另一个应用程序?例如,当我单击应用程序中的按钮时,我想运行 Facebook
- javascript - 轮播标题消失
- c - read() - 如果在包括递归循环的循环中使用,则检查缓冲区边界
- jquery - 更改时自定义单选框 CSS
- json - PYTHON3:如何将带有 unicode 字符的字节字符串打印到控制台?并在 json.load(..) 中使用?