使用 <filesystem> C++17 时出错
Errors using <filesystem> C++17
我正在尝试搜索一个目录,并以非平台依赖性方式列出该目录中的所有条目。为此,我尝试使用std ::文件系统,但是,尝试使用在此处定义的函数时,我有很多编译错误。
这是我要运行的示例代码(编辑:即使我删除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 的输出:
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。如果需要,更新路径。我遇到了相同的问题,它解决了。
相关文章:
- C++17复制构造函数,在std::unordereded_map上进行深度复制
- 访问者访问变体并返回不同类型时出错
- 在Linux for Windows上编译C++代码时出错
- 读取文件的最后一行并输入到链接列表时出错
- 如何在c++17中制作一个模板包装器/装饰器
- 重载操作程序时出错>>用于类中的字符串 memebr
- 调用专用模板时出错"no matching function for call to [...]"
- C++-试图将函数指针推回到另一个CPP文件中的矢量时出错
- 枚举环境变量的惯用C++14/C++17方法
- LINK 尝试使用 OpenSSL evp aes 256 c++ 时出错
- 在Google Kick start中提交时出错
- 在c++中访问int到类对象的映射时出错
- gcc和c++17的过载解析失败
- 数据成员SFINAE的C++17测试:gcc vs clang
- 我可以将一个用clang c++11编译的对象与另一个用c++17编译的对象链接起来吗
- C++17中的并行执行策略
- 分段错误当我试图运行程序时出错
- 使用dynamic_cast和构造函数时出错
- 使用 <filesystem> C++17 时出错
- wxwidget 3.1.2 代码块 17.04 在链接步骤中出错