1.下载vscode

先下载vscode,下载完成后安装c/c++插件

vscode lua提示代码_vscode lua提示代码

2.安装MinGW2.1.下载MinGW

MinGW下载地址

2.2.安装MinGW2.2.1

vscode lua提示代码_c++_02

2.2.2

vscode lua提示代码_c++_03

注:这里我修改了安装路径,默认即可,当然后面设置要注意。并且继续点击continue2.2.3:对于箭头所指的每一项,右键Mark for installation,我这里选择了全部安装

vscode lua提示代码_VSCode_04

2.2.4:点击installation->apply changes

vscode lua提示代码_c++_05

然后就慢慢等吧,博主安装了十几分钟。

2.2.5:将

D:\Software_install\MinGW\bin

加入系统环境变量,这时候可以cmd中运行gcc -v,如出现下图则证明MinGW安装成功

vscode lua提示代码_include_06

3.配置VScode3.1 先创建一个文件夹,路径任意,然后使用 VSCode打开3.2 在这个文件夹里创建一个test.cpp的cpp文件用来接下来的测试
#include <iostream>
int main(){
    std::cout<<("Hello,world");
    return 0;
}
3.3 配置

vscode lua提示代码_c++_07

vscode lua提示代码_c++_08

vscode lua提示代码_cpp_09

注:第四步如果不出现也可以,这时候经过以上操作就会打开launch.json文件,将下面的代码覆盖原代码,ctrl + s 保存
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++.exe build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "D:\\Software_install\\MinGW\\bin\\gdb.exe",
            "preLaunchTask": "g++",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}
注:miDebuggerPath 与前面MinGW的安装路径有关,你只需要找到MinGW\bin\gdb.exe这个文件即可,注意里面路径是\\,且路径和关键字都用""引号引起来,每行结尾有个,逗号。3.4 切换到test.cpp,按F5调试,在弹出框中选择

vscode lua提示代码_c++_10

vscode lua提示代码_vscode lua提示代码_11

在弹出的task.json文件中将下面的代码覆盖即可,并ctrl + s 保存

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "g++",
            "command": "D:\\Software_install\\MinGW\\bin\\g++.exe",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "D:\\Software_install\\MinGW\\bin"
            },
            "problemMatcher": [
                "$gcc"
            ]
        },
        {
            "type": "shell",
            "label": "g++.exe build active file",
            "command": "D:\\Software_install\\MinGW\\bin\\g++.exe",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "D:\\Software_install\\MinGW\\bin"
            }
        }
    ]
}
4 遇到的问题4.1 如果出现这种情况,#include <iostream>,左边有个灯泡,这时候可以点击灯泡后跳出配置文件,修改其中的Win32的"includePath"如下,和上文一样,根据自己的路径进行调整即可。

这是我的配置,你也可以覆盖后 ctrl+s 保存

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "D:/Software_install/MinGW/include/*",
                "D:/Software_install/MinGW/lib/gcc/mingw32/8.2.0/include/*",
                "D:/Software_install/MinGW/lib/gcc/mingw32/8.2.0/include/c++/*",
                "D:/Software_install/MinGW/lib/gcc/mingw32/8.2.0/include/c++/mingw32/*",
                "D:/Software_install/MinGW/lib/gcc/mingw32/8.2.0/include/c++/backward/*"
            ],
            "browse": {
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            },

            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "8.1",
            "compilerPath": "D:/Software_install/VisualStudio/VC/bin/cl.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "msvc-x64"
        }
    ],
    "version": 4
}
4.2 如果出现namespace has no member错误

点击vscode界面:file->Preferences->Settings->在搜索栏中搜索intelliSenseEngine->在C_Cpp.intelliSenseEngine的下拉菜单中选择Tag Parser即可,如图

vscode lua提示代码_c++_12

5 运行cpp代码

可以在vscode中下载code runner插件,这样右键test.cpp,点击run code即可

注:在此之间,当编写了cpp代码后要先保存,否则运行无反应,vscode必须先ctrl+s保存代码后再run code才有输出

vscode lua提示代码_include_13

6 注意事项

vscode对于每个新文件夹都需要进行配置,所以这里建议创建了一个文件夹后先对这个文件夹进行配置,以后都在这个文件夹中建立子文件夹,或者每次创建新文件夹时将配置过的文件夹中产生的.vscode中的所有文件复制到新文件夹中再用vscode进行打开