最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c++ - filesystem was not declared in this scope - Stack Overflow

programmeradmin3浏览0评论

error: 'filesystem' was not declared in this scope; did you mean 'system'?

#include <iostream>
#include <filesystem>
#include <fstream>

int main() {

    std::cout << "Current working directory: " << std::filesystem::current_path() << std::endl;

    return 0;

}

I've tried adding using namespace std that didn't help either. I have g++ 13.2.0 and CLang 16.0.0.

iostream and fstream are working, filesystem is not.

Thank you in advance.

error: 'filesystem' was not declared in this scope; did you mean 'system'?

#include <iostream>
#include <filesystem>
#include <fstream>

int main() {

    std::cout << "Current working directory: " << std::filesystem::current_path() << std::endl;

    return 0;

}

I've tried adding using namespace std that didn't help either. I have g++ 13.2.0 and CLang 16.0.0.

iostream and fstream are working, filesystem is not.

Thank you in advance.

Share Improve this question edited Mar 15 at 8:18 Ted Lyngmo 119k7 gold badges84 silver badges136 bronze badges asked Mar 15 at 1:00 Husam ChekfaHusam Chekfa 732 silver badges12 bronze badges 9
  • I thought g++ 13.2 should default to c++17 allowing std::filesystem to be available. Are you on macOS? – drescherjm Commented Mar 15 at 1:07
  • I'm on Windows 10 – Husam Chekfa Commented Mar 15 at 1:08
  • 1 Fixed thanks for your help everyone, it was a problem with the make file for some reason it was defaulted at C++ 14 when the file was made – Husam Chekfa Commented Mar 15 at 1:21
  • 1 And that's the missing piece of information we needed. Somehow you weren't getting C++17 and that'll do it. – user4581301 Commented Mar 15 at 1:22
  • 1 Thank you for the answer on the platform, but it is irrelevant, as you can see. Thank you for looking the then answer and accepting it. – Sergey A Kryukov Commented Mar 15 at 1:36
 |  Show 4 more comments

1 Answer 1

Reset to default 4

It works only since C++ 17:

#include <iostream>
#include <filesystem>

int main() {
    std::cout << "Current working directory: " << std::filesystem::current_path() << std::endl;
    return 0;
}

So, you need to use C++ 17 or later. See also: Filesystem library.

Note that you need only two #include lines. You are not using #include <fstream> here.

发布评论

评论列表(0)

  1. 暂无评论