vscode运行cpp文件:检测到 #include 错误。请更新 includePath。已为此翻译单元(E:\C++ Code\test1\test1\test1.cpp)禁用波形曲线。

刚为vscode配置好C++编译环境准备刷leetcode,结果写cpp文件时发现#include头文件总是报错:

我就很迷惑了,#include也能出错,找了半天教程,特此记录:

首先vscode配置C++环境得有一个C/C++扩展插件,然后插件安好了,在你经常写代码的文件夹下创建一个.vscode文件夹,比如我的c++代码就保存在E:\C++ Code里面:

vscode运行cpp文件:检测到 #include 错误。请更新 includePath。已为此翻译单元(E:\C++ Code\test1\test1\test1.cpp)禁用波形曲线。_第1张图片

.vscode里面有三个文件,内容如下(虽然我记得有些可以在运行出错的时候提示生成的):

c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "E:\\mingw64\\bin\\g++.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}

注意:里面的“compilePath”值要改为你的mingw的路径,路径中 '\'要替换为'\\';里面的"intelliSenseMode"的值要改为"gcc-x64"和编译器路径兼容。

launch.json:

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++.exe - 生成和调试活动文件",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "E:\\mingw64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "task g++"
        }
    ]
}

注意里面的 "miDebuggerPath"路径改为你对应的mingw的路径

task.json:

{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "shell",
			"label": "task g++",
			"command": "E:\\mingw64\\bin\\g++.exe",
			"args": [
				"-g",
				"${file}",
				"-o",
				"${fileDirname}\\${fileBasenameNoExtension}.exe"
			],
			"options": {
				"cwd": "E:\\mingw64\\bin"
			},
			"problemMatcher": [
				"$gcc"
			],
			"group": "build"
		}
	]
}

注意"label"的值要和launch.json中"preLaunchTask"的值一致。

然后你可以在写代码的文件下新建一个cpp用来测试:

vscode运行cpp文件:检测到 #include 错误。请更新 includePath。已为此翻译单元(E:\C++ Code\test1\test1\test1.cpp)禁用波形曲线。_第2张图片

插一句编译器提示安装vcpkg就很有毒。

 

参考文章:

https://blog.csdn.net/qq_37960007/article/details/104455239?depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-4&utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-4

https://www.cnblogs.com/baihualiaoluan/p/10661669.html

 

你可能感兴趣的:(日常问题解决)