- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
许多人(例如 1 、 2 )询问如何获得 std::filesystem::directory_iterator
去工作,但在我读完这些之后我仍然遇到了麻烦。
我正在尝试构建一个小型静态库。在将目录迭代器添加到一些源文件中后,我更新了我的 gcc,并添加了 -lstdc++fs
有点,但似乎没有任何效果,因为我不断收到错误消息
fatal error: filesystem: No such file or directory
#include <filesystem>
如果我输入 gcc --version
, 我得到
gcc (Ubuntu 7.3.0-16ubuntu3) 7.3.0
Copyright (C) 2017 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.
如果我输入 gcc-8 --version
我明白了
gcc-8 (Ubuntu 8.1.0-1ubuntu1) 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.
这是我编译所有内容的小 shell 脚本。我也尝试了一些其他变体。
EIGEN=/usr/include/eigen3
cd ./bin
for file in ../src/*cpp; do
g++ -std=c++11 -fPIC -c -I$EIGEN -I../include -O3 $file "-lstdc++fs"
done
ar crv libfoo.a *.o
cd ..
最佳答案
<filesystem>
仅随 C++17 添加到 C++ 标准库。
g++ 7.3
(您的默认 g++
)不完全符合此分数。它不会找到 <filesystem>
与 -std=c++17
.按理说不会定位<filesystem>
与 -std=c++11
,您发布的脚本要求它这样做。但它会定位<experimental/filesystem>
与 std=c++11
或以后。
你还有g++-8
(大概是 g++ 8.1/8.2)。它将找到 <filesystem>
与 std=c++17
:
$ cat main.cpp
#include <filesystem>
int main()
{
return 0;
}
$ g++-8 -std=c++17 main.cpp && echo $?
0
有趣的是,它也会对 std=c++11
执行此操作或 std=c++14
:
$ g++-8 -std=c++11 main.cpp && echo $?
0
$ g++-8 -std=c++14 main.cpp && echo $?
0
与 g++-8
您不需要链接过渡库 libstdc++fs
.
(顺便说一句,聪明的钱总是在编译时启用严格的警告: ... -Wall -Wextra ...
)
关于c++ - `std::filesystem::directory_iterator` 编译器问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52472023/
自从我使用 C++ 以来已经有一段时间了,请原谅我的新手问题。 我编写了以下代码来获取目录内容的列表,它运行良好: for (directory_iterator end, dir("./");
我正在尝试遍历目录并读取其中的图像,同时允许跳过每第 n 个文件。 我的代码目前看起来像这样: // Count number of files in directory and reserve me
这是我的代码: #include #include int main(int argc, char *argv[]) { auto iter = std::filesystem::dire
编辑:我使用的是 std::tr2::sys 而不是 boost 的文件系统 我正在开发一个简单的应用程序,它可以扫描计算机上的目录并返回有关这些文件的统计信息。可以通过两种方式调用扫描:递归和非递归
我想重命名目录中的文件。目录中有 52 个文件夹。每个文件夹都有不同的名称,每个文件夹中有大约 40 个文件。我想提取特定文件夹的名称并将该名称附加到该特定文件夹中的文件名称。 当每个文件夹中只有 3
所以我写了一个小程序来试用 Boost Filesystem。我的程序将写入当前路径中有多少个文件,然后是文件名。这是我的程序: #include #include using namespace
我一直在尝试使用通过快速谷歌搜索找到的这个示例遍历目录: namespace bf = boost::filesystem; bf::path p("somedir"); bf::directory_
我已经在 directory_iterator page 上复制了示例代码,所以这就是我所拥有的: #include "pch.h" //for visual studios benefit #inc
我有以下代码: for (const auto& x : std::filesystem::directory_iterator(dir)) { // do stuff with x } di
我正在遍历一个目录,当某个项目符合某些条件时,我将其删除。我可以在循环内安全地执行此操作,还是必须将路径保存在数组中并稍后删除? 我在boost::filesystem docs中没有找到相关信息.
有些东西没有意义。根据我读过的内容,你使用 std::filesystem 是这样的: #include #include #include int main() { auto it
许多人(例如 1 、 2 )询问如何获得 std::filesystem::directory_iterator去工作,但在我读完这些之后我仍然遇到了麻烦。 我正在尝试构建一个小型静态库。在将目录迭代
我在 gcc 6.3.1 中使用实验性 std::filesystem 实现,遇到了一些关于 std::experimental::filesystem::directory_iterator #in
以下代码递归地遍历给定目录并每次以相同顺序打印其内容。 是否可以改变目录迭代器以随机方式打印目录内容(而不是使用 vector 存储结果然后随机打印 vector 内容)? #include #in
我正在编写一个程序,它获取目录中的所有文件名并将它们放入一个数组中。我遇到的问题是 operator++() 显示错误并且不会增加迭代器。任何帮助将不胜感激。 #include #include
我知道这听起来很愚蠢,但看看这个简单的例子(工作目录应该有多个项目): #define BOOST_FILESYSTEM_VERSION 3 #include #include int main(
我正在尝试使用其 insert(const_iterator pos, InputIt first, InputIt last) 将转换后的目录条目范围插入 vector 中成员函数模板。 不幸的是,
我正在尝试获取最后一个文件名。 下面的代码非常优雅。但它正在遍历目录中的所有文件。 是否可以在不迭代的情况下获取最后一个文件? #include std::string latestFileName
我正在使用 boost 的文件系统和 std::max_element() 来查找给定目录中名称最长的文件: #include #include #include #include #incl
我正在尝试学习如何使用 Boost C++ 库,但我遇到了一个问题。运行以下 boost::filesystem 教程代码时: #include #include using std::cout;
我是一名优秀的程序员,十分优秀!