各种乱七八糟的 VS2022 的错误记录:
报错代码,截取了部分:
bool saveImageToDirectory(const std::string& directoryPath, const cv::Mat& image, const std::string& imageName) {
try {
std::filesystem::create_directories(directoryPath);
}
catch (const std::filesystem::filesystem_error& e) {
std::cerr << "创建目录失败: " << e.what() << std::endl;
return false;
}
其中 std::filesystem 这句报错,错误如题。解决办法:
- 右键单击项目,在“属性”中选择“配置属性”。
- 转到“C/C++” > “语言”。
- 在“C++语言标准”中选择
/std:c++17
或更高版本。
如果仍然有错,确保自己的头文件包含:
#include <filesystem>
#include <iostream>
#include <opencv2/opencv.hpp> // 如果使用 OpenCV