Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/149.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++;代码块升级到C++;17罐';不要使用std::文件系统 我需要能够在目录中列出文件,所以我试图把我的C++版本升级到C++ 17,这样我就可以使用文件系统。为此,我遵循了在中概述的步骤_C++_Codeblocks - Fatal编程技术网

C++;代码块升级到C++;17罐';不要使用std::文件系统 我需要能够在目录中列出文件,所以我试图把我的C++版本升级到C++ 17,这样我就可以使用文件系统。为此,我遵循了在中概述的步骤

C++;代码块升级到C++;17罐';不要使用std::文件系统 我需要能够在目录中列出文件,所以我试图把我的C++版本升级到C++ 17,这样我就可以使用文件系统。为此,我遵循了在中概述的步骤,c++,codeblocks,C++,Codeblocks,我不需要做太多更改,代码块20.03和Mingw8.1.0已经安装好了。当我构建wxWidgets时,MinGW已经在我的路径中。设置->编译器…->工具链可执行文件选项卡我不需要做任何更改,它在代码块中显示为: 我也检查了在C++程序中使用C++ 17的框,比如S/< 我按照说明在网站上运行了测试程序,得到了“True!” 但是,当我将基本测试程序更改为此时,要尝试使用文件系统读取目录中的文件,我会遇到一个错误: #include <iostream> #include <

我不需要做太多更改,代码块20.03和Mingw8.1.0已经安装好了。当我构建wxWidgets时,MinGW已经在我的路径中。设置->编译器…->工具链可执行文件选项卡我不需要做任何更改,它在代码块中显示为:

我也检查了在C++程序中使用C++ 17的框,比如S/<

我按照说明在网站上运行了测试程序,得到了“True!”

但是,当我将基本测试程序更改为此时,要尝试使用文件系统读取目录中的文件,我会遇到一个错误:

#include <iostream>
#include <filesystem>

using namespace std;

int main()
{
    const int i=90;

    if constexpr (i) //'if constexpr' is part of C++17
    {
        cout << "True!";
    }
    else
    {
        cout<<"False" ;
    }

    std::string path = "../MagicProgCPP/files/debug images/";
    for (const auto & entry : filesystem::directory_iterator(path))
    {
        cout << entry.path() << std::endl;
    }


    cin.get();
    return 0;
}

我做错了什么?谢谢

这个问题似乎是mingw 8.1中的一个已知错误。错误报告如下:

并且在同一位置有错误:

operator != is declared and defined in line 550, but referenced in line 237.

The problem is triggered by operator/= in line 233:

    path& operator/=(const path& __p)
    {
#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
      if (__p.is_absolute()
      || (__p.has_root_name() && __p.root_name() != root_name()))
    operator=(__p);
      else
    {
      string_type __pathname;
      if (__p.has_root_directory())
        __pathname = root_name().native();
      else if (has_filename() || (!has_root_directory() && is_absolute()))
        __pathname = _M_pathname + preferred_separator;
      __pathname += __p.relative_path().native(); // XXX is this right?
      _M_pathname.swap(__pathname);
      _M_split_cmpts();
    }
bug报告说这在master中已修复,这意味着您需要安装一个应用了修复的mingw版本。我认为最好的方法是将mingw升级到8.1以上的版本


在上面的主要问题中评论说,以下链接提供了有关如何安装mingw的说明:

自2018-07年以来,缺陷78870已修复
您应该将以下库添加到项目选项->链接器设置->链接库:
stdc++fs
。 我试着用MinGW gcc 8.1.0(通过代码块)编译你的代码,一切都很好(显然是用另一条路径,因为我没有和你相同的目录)。 您还可以添加对搜索目录是否存在的检查,如下所示:

namespace fs = std::filesystem;
std::string mypath { "../MyDir" };
if(fs::exists(mypath))
{
    for(const auto & entry : fs::directory_iterator(path))
    {
        cout << entry.path() << std::endl;
    }
}
名称空间fs=std::filesystem;
std::字符串mypath{../MyDir};
如果(fs::exists(mypath))
{
for(const auto&entry:fs::directory\u迭代器(path))
{

我能相信是这个编译器错误:我希望你必须将mingw升级到比8.1Ah更新的版本好的,谢谢,是的,错误报告看起来和我所经历的一模一样。谢谢你的帮助,它是最新的,有一个优秀的包管理器,所以你可以轻松地保持最新。它还有一个优秀的工具和库生态系统ies,这样你就不必浪费时间单独下载和定制SSL、Boost和cURL(大多数情况下)之类的产品。非常棒而且省时。@drescherjm不妨将其正式化为一个答案。希望它能让下一个遇到它的人更容易理解。
operator != is declared and defined in line 550, but referenced in line 237.

The problem is triggered by operator/= in line 233:

    path& operator/=(const path& __p)
    {
#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
      if (__p.is_absolute()
      || (__p.has_root_name() && __p.root_name() != root_name()))
    operator=(__p);
      else
    {
      string_type __pathname;
      if (__p.has_root_directory())
        __pathname = root_name().native();
      else if (has_filename() || (!has_root_directory() && is_absolute()))
        __pathname = _M_pathname + preferred_separator;
      __pathname += __p.relative_path().native(); // XXX is this right?
      _M_pathname.swap(__pathname);
      _M_split_cmpts();
    }
namespace fs = std::filesystem;
std::string mypath { "../MyDir" };
if(fs::exists(mypath))
{
    for(const auto & entry : fs::directory_iterator(path))
    {
        cout << entry.path() << std::endl;
    }
}