首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >C++ -没有运算符"<<“与这些操作数directory_iterator()匹配

C++ -没有运算符"<<“与这些操作数directory_iterator()匹配
EN

Stack Overflow用户
提问于 2018-11-22 19:06:04
回答 3查看 457关注 0票数 3

我已经复制了directory_iterator page上的示例代码,所以这是我所拥有的:

代码语言:javascript
复制
#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
}

错误消息是:

代码语言:javascript
复制
Severity    Code    Description Project File    Line    Suppression State
Error (active)  E0349   no operator "<<" matches these operands 

由于我是C++的新手,我可能弄错了,但我对错误的理解基本上是,在我的例子中,p是不能使用cout打印到控制台的东西。

如果我直接在页面上运行这个示例,那么它就不会有什么问题,这也是我不希望看到的。所以问题是,为什么我会看到这个错误?

我使用的是最新版本的Visual Studio,以及C++ 2017。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53429574

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档