C++ C++;-“无操作员”<<&引用;匹配这些操作数目录\迭代器()
我已经在上复制了示例代码,所以我有:C++ C++;-“无操作员”<<&引用;匹配这些操作数目录\迭代器(),c++,visual-studio-2017,C++,Visual Studio 2017,我已经在上复制了示例代码,所以我有: #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
#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
}
#包括“pch.h”/
#包括
#包括
#包括
名称空间fs=std::filesystem;
int main()
{
创建目录(“沙盒/a/b”);
std::ofstream(“sandbox/file1.txt”);
std::ofstream(“sandbox/file2.txt”);
for(auto&p:fs::directory\u迭代器(“沙盒”))
std::cout对于Visual Studio 2017(如果我没有弄错的话,请参阅15.8和15.9),文件系统
仅公开实验版本,因此请使用:
namespace fs = std::experimental::filesystem;
更改此项:
namespace fs = std::filesystem;
为此:
namespace fs = std::experimental::filesystem;
因为VS 17使用了一个实验版本的文件系统
使用std::experimental
命名空间:
namespace fs = std::experimental::filesystem;
directory\u entry
没有直接的流媒体支持;它通过path
的操作符获取。嘿,彼得,我相信你是对的,但我看不出这个答案比我的答案和Matthieu的答案更进一步。:/嗯,在阅读了你的T.C之后,我现在不确定是否正确,回答很好!我不知道我是否能够确定是否使用path()
或实验性
namspace比另一个更正确。因此,我不会接受答案,直到我对主题有了更多的了解。但是,它们都可以工作,呈现稍微不同的输出。使用path()
将呈现“”在每个查找周围,而实验性名称空间将不会。但是数据仍然是相同的。实验性为您提供了较旧的文件系统TS实现,它是。
namespace fs = std::experimental::filesystem;