c ++ 17`filesystem`不是名称空间名称 [英] c++17 `filesystem` is not a namespace-name

查看:928
本文介绍了c ++ 17`filesystem`不是名称空间名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道为什么在以下代码中找不到命名空间文件系统

I am wondering why in the following code, the namespace filesystem is not found:


g ++ -std = c ++ 17 main.cpp -lstdc ++

g++ -std=c++17 main.cpp -lstdc++



// #include <filesystem>   <- error, so changed to the following:
#include <experimental/filesystem>

namespace fs = std::filesystem;

int main()
{
    return 0;
}

错误:

main.cpp:3:21: error: ‘filesystem’ is not a namespace-name
 namespace fs = std::filesystem;
                     ^
main.cpp:3:31: error: expected namespace-name before ‘;’ token
 namespace fs = std::filesystem;




gcc版本5.4.0 20160609(Ubuntu 5.4.0-6ubuntu1〜 16.04.5)

gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.5)


推荐答案

GCC 5.4.0于2016年6月发布;在采用C ++ 17标准之前的一年多。它及其libstdc ++版本对C ++ 17的支持非常有限。您可以在此处中看到GCC添加C ++ 17语言功能的时间,以及libstdc ++添加时的时间C ++ 17标准库功能此处

GCC 5.4.0 was released in June of 2016; over a year before the C++17 standard was adopted. It and its version of libstdc++ have very limited C++17 support. You can see when GCC added C++17 language features here and when libstdc++ added C++17 standard library features here.

在GCC 5.4发布时,文件系统库尚未在 std :: filesystem 名称空间。它以及任何其他< experimental /...& gt;该版本中包含的标头位于 std :: experimental 命名空间中。

At the time of GCC 5.4's release, the filesystem library was not yet implemented in the std::filesystem namespace. It, along with any other <experimental/...> headers that are included in that version, are in the std::experimental namespace.

这篇关于c ++ 17`filesystem`不是名称空间名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆