我试图在我的代码中包含多个 hpp 文件,但是我的 c_cpp_properties.json 中的包含路径选项似乎无法正常工作。我一直收到“没有这样的文件或目录...”,即使那里有正确的文件。
我已将路径添加到 c_cpp_properties.json 文件的 includePath 部分,但它仍然找不到文件。
包含主文件的一部分:
#include <iostream>
#include<conio.h>
#include <D:\OpenCV\opencv\build\include\opencv2\core\core.hpp>
#include <D:\OpenCV\opencv\build\include\opencv2\highgui.hpp>
#include <D:\OpenCV\opencv\build\include\opencv2\imgproc\imgproc.hpp>
c_cpp_properties.json 文件:
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"D:/OpenCV/opencv/build/include",
"D:/OpenCV/opencv/sources/modules/core/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.17763.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx64/x64/cl.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "msvc-x64"
}
],
"version": 4
}```
The file should run, but this error is causing it not to.
最佳答案
如果 c_cpp_properties.json
包含编译时使用的属性,您的 #include
应该看起来像这样:
#include <iostream>
#include <conio.h>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include
中的单个反斜杠很可能被解释为 escape sequences 的开始这不会导致正确的路径。
关于c++ - 如何修复由于 C++ includePath 导致的 "No such file or directory..."错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56527724/