c++ - VS2019 上的 c++ 目录迭代器异常-已更改语言设置,还有什么要尝试的,2019 年是否已更改?
问题描述
我从 2017 年开始迁移到 vs2019,它带来了一些小而烦人的挑战......
其中之一是我为遍历目录并将文件路径推送到数组中而开发的这段代码。
我已将语言设置更新为属性页上的最新草稿,允许我删除命名空间中的::experimental。
代码会构建,但在调试和单步执行时,当迭代器尝试初始化到目录路径时会引发异常。
我错过了什么,因为几天前在 vs2017 上工作正常。
我检查了图书馆,我想我正在提供它所要求的东西?
解决方案
如果有效,您能否在您的机器上检查以下内容和反馈(通过评论)?
#include <iostream>
#include <filesystem>
#include <vector>
#include <iterator>
namespace fs = std::filesystem;
int main() {
// The start path
const fs::path startPath{ "C:\\temp\\" };
std::vector<std::string> files{};
// Get all path names as string
std::transform(fs::directory_iterator(startPath), {}, std::back_inserter(files), [](const fs::directory_entry& de) { return de.path().string(); });
// Output all files
std::copy(files.begin(), files.end(), std::ostream_iterator<std::string>(std::cout, "\n"));
return 0;
}
因为这可以在我的机器上使用 Microsoft Visual Studio Community 2019 版本 16.5.2
推荐阅读
- python - 将数据添加到现有的 Excel 工作表
- angular - 我如何在 ion-toggle 上调用两个不同的 highcharts?
- php - ErrorException htmlspecialchars() 期望参数 1 是字符串,给定数组
- python - 如何从 python 中的网络套接字解压缩 LZW 数据包?
- c# - 如何从 App.xaml.cs 导航到其他页面?
- entity - 有没有办法在 Draftjs 中添加牢不可破的实体?
- javascript - 为什么在循环中使用变量和直接调用索引有区别?
- django - 如何确定向特定听众群发送消息?
- c# - Microsoft.CodeAnalysis.FxCopAnalyzers 和 Microsoft.CodeAnalysis 之间有什么区别?
- firebase - Firebase 本机与 Ionic3 应用程序中的 Firebase JS 冲突(推送通知启用问题)