admin管理员组文章数量:1429968
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
1 Answer
Reset to default 4It 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.
本文标签: cfilesystem was not declared in this scopeStack Overflow
版权声明:本文标题:c++ - filesystem was not declared in this scope - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744626752a2616305.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论