簡體   English   中英

錯誤使用<filesystem> C++17

[英]Errors using <filesystem> C++17

我正在嘗試搜索目錄並以非平台相關的方式列出該目錄中的所有條目。 為此,我嘗試使用 std::filesystem,但是,在嘗試使用那里定義的函數時,我遇到了大量編譯錯誤。

這是我嘗試運行的示例代碼(編輯:即使我刪除了 for 循環並只保留“返回 0”,我也會收到相同的錯誤):

#include <iostream>
#include <string>
#include <filesystem>

int main()
{
   for (const auto & entry : std::filesystem::directory_iterator("D:\\fac_2ano2semestre"))
        std::cout << entry.path() << std::endl;

    return 0;
}

這是 g++ --version 的輸出:

g++.exe (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

這是我的 Makefile 中的一個示例(我也試過 -lstdc++fs):

# Compiler
CXX := g++

# Add whatever compiler flags you want.
CXXFLAGS := -std=c++17 
CXXFLAGS += -Wall -g 

# You MUST keep this for auto-dependency generation.
CXXFLAGS += -MMD

我收到的錯誤的一小部分:

g++ -std=c++17  -Wall -g  -MMD   -c -o src/app.o src/app.cpp
In file included from D:/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/filesystem:37,
                 from src/app.cpp:3:
D:/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h: In member function 'std::filesystem::__cxx11::path& std::filesystem::__cxx11::path::operator/=(const std::filesystem::__cxx11::path&)':
D:/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:237:47: error: no match for 'operator!=' (operand types are 'std::filesystem::__cxx11::path' and 'std::filesystem::__cxx11::path')
    || (__p.has_root_name() && __p.root_name() != root_name()))
                               ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
In file included from D:/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/iosfwd:40,
                 from D:/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/ios:38,
                 from D:/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/ostream:38,
                 from D:/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/iostream:39,
                 from src/app.cpp:1:
D:/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/postypes.h:221:5: note: candidate: 'template<class _StateT> bool std::operator!=(const std::fpos<_StateT>&, const std::fpos<_StateT>&)'
     operator!=(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs)
     ^~~~~~~~
D:/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/postypes.h:221:5: note:   template argument deduction/substitution failed:
In file included from D:/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/filesystem:37,
                 from src/app.cpp:3:
D:/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:237:60: note:   'std::filesystem::__cxx11::path' is not derived from 'const std::fpos<_StateT>'
    || (__p.has_root_name() && __p.root_name() != root_name()))
                                                            ^
In file included from D:/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/stl_algobase.h:64,
                 from D:/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/char_traits.h:39,
                 from D:/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/ios:40,
                 from D:/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/ostream:38,
                 from D:/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/iostream:39,
                 from src/app.cpp:1:
D:/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/stl_pair.h:456:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator!=(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)'
     operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
     ^~~~~~~~
D:/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/stl_pair.h:456:5: note:   template argument deduction/substitution failed:
In file included from D:/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/filesystem:37,
                 from src/app.cpp:3:

從這里下載最新版本的編譯器: http : //winlibs.com/然后只需將其解壓縮以覆蓋當前的 mingw-64。 如果需要,更新 PATH。 我有同樣的問題,它修復了它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM