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

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

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

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

.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用来测试:

插一句编译器提示安装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

 

  • 18
    点赞
  • 50
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
这个错误提示是因为编译器无法找到 iostream文件,iosteam 是 C++ 中的标准输入输出流库,通常用于控制台程序中。为了解决这个错误,你需要确保已经正确安装了 C++ 编译器和标准库,并且在编译器include path 中包含了 iostream文件所在的路径。 如果你使用的是 Visual Studio Code,可以在项目根目录下创建一个名为 ".vscode" 的文件夹,然后在该文件夹下创建一个名为 "c_cpp_properties.json" 的文件,并在该文件中添加以下内容: ``` { "configurations": [ { "name": "Win32", "includePath": [ "${workspaceFolder}/**" ], "defines": [], "compilerPath": "C:/MinGW/bin/gcc.exe", "cStandard": "c11", "cppStandard": "c++17", "intelliSenseMode": "gcc-x64", "browse": { "path": [ "${workspaceFolder}" ], "limitSymbolsToIncludedHeaders": true, "databaseFilename": "" } } ], "version": 4 } ``` 其中,"compilerPath" 对应你的 C++ 编译器的安装路径,"cStandard" 对应你所使用的 C 标准的版本,"cppStandard" 对应你所使用的 C++ 标准的版本。你需要根据自己的实际情况进行配置。 如果你使用的是其他的 C++ 编译器,可以参考其文档或者官方网站,查找如何设置 include path。另外,你也需要确保你的代码中正确地包含了 iostream文件,例如: ``` #include <iostream> int main() { std::cout << "Hello, World!"; return 0; } ``` 如果你仍然无法解决这个问题,可以尝试重新安装 C++ 编译器和标准库,或者在网上搜索相关的解决方案。
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值