我已经复制了directory_iterator page上的示例代码,所以这是我所拥有的:
#include "pch.h" //for visual studios benefit
#include <fstream>
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
fs::create_directories("sandbox/a/b");
std::ofstream("sandbox/file1.txt");
std::ofstream("sandbox/file2.txt");
for (auto& p : fs::directory_iterator("sandbox"))
std::cout << p << '\n'; //this line on the first '<<' is where the error occurs
fs::remove_all("sandbox");
return 0; //included by me
}
错误消息是:
Severity Code Description Project File Line Suppression State
Error (active) E0349 no operator "<<" matches these operands
由于我是C++的新手,我可能弄错了,但我对错误的理解基本上是,在我的例子中,p
是不能使用cout
打印到控制台的东西。
如果我直接在页面上运行这个示例,那么它就不会有什么问题,这也是我不希望看到的。所以问题是,为什么我会看到这个错误?
我使用的是最新版本的Visual Studio,以及C++ 2017。
https://stackoverflow.com/questions/53429574
复制相似问题