[英]'Filesystem' member not in 'std' namespace
I have some code intending to get the file size of a PNG image (from a different stack overflow post).我有一些代码打算获取 PNG 图像的文件大小(来自不同的堆栈溢出帖子)。
#include <fstream>
#include <cstring>
#include <cstddef>
#include <filesystem>
const char* INPUT_FILENAME = "test.png";
using namespace std;
int main()
{
std::ifstream file;
size_t size = 0;
std::cout << "Attempting to open " << INPUT_FILENAME << std::endl;
file.open( INPUT_FILENAME, std::ios::in | std::ios::ate );
char* data = 0;
file.seekg( 0, std::ios::end );
// size = file.tellg();
size = std::filesystem::file_size(INPUT_FILENAME);
std::cout << "File size: " << size << std::endl;
file.seekg( 0, std::ios::beg );
data = new char[ size - 8 + 1 ];
file.seekg( 8 ); // skip the header
file.read( data, size );
data[ size ] = '\0';
std::cout << "Data size: " << std::strlen( data ) << std::endl;
}
Upon running I get the error `no member named 'filesystem' in namespace 'std';运行时出现错误“命名空间“std”中没有名为“文件系统”的成员; did you mean 'std::__fs::filesystem'.你的意思是'std::__fs::filesystem'。 Even attempting to use the latter function results in errors of its own.即使尝试使用后者 function 也会导致其自身的错误。 I need help figuring if this is an issue with not having all the correct packages installed, or possibly my IDE settings?我需要帮助确定这是否是未安装所有正确软件包的问题,或者可能是我的 IDE 设置的问题? I should note I am running on a MacBook OS 11.2.3 and QtCreator 5.14.2.我应该注意我在 MacBook OS 11.2.3 和 QtCreator 5.14.2 上运行。
The error is saying that your compiler doesn't support std::filesystem.错误是说您的编译器不支持 std::filesystem。
There IS such a thing as " std::filesystem "... depending on your compiler.有诸如“ std::filesystem ”之类的东西……取决于您的编译器。
This link might help:此链接可能会有所帮助:
https://stackoverflow.com/a/49192230/421195 https://stackoverflow.com/a/49192230/421195
CONFIG += c++17
can be used with Qt 5.12 and later.CONFIG += c++17
可与 Qt 5.12 及更高版本一起使用。For Qt 5.11 and earlier, it is not a recognized QMake flag and you have to get your hands a bit dirty.对于 Qt 5.11 及更早版本,它不是一个公认的 QMake 标志,你必须弄脏你的手。
Adding
QMAKE_CXXFLAGS += -std=c++17
does the job for GCC & Clang;添加QMAKE_CXXFLAGS += -std=c++17
为 GCC & Clang 完成工作; for MSVC you will probably need to specify/std:c++17
or/std:c++latest
对于 MSVC,您可能需要指定/std:c++17
或/std:c++latest
See also Compile With C++17 Mac另请参阅使用 C++17 Mac 编译
If neither option works, please post back with your specific compiler version.如果这两个选项都不起作用,请使用您的特定编译器版本发回。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.