• Visual Studio Code配置c/c++环境


    1.创建项目目录

    d:\>mkdir d:\c语言项目\test01
    
    • 1

    2.vscode打开项目目录

    在这里插入图片描述

    3.项目中添加文件

    在这里插入图片描述

    4.文件内容

    #include 
    using namespace std;
    
    int main(){
        cout << "hello world" << endl;
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    在这里插入图片描述

    5.配置编译器

    快捷键:Ctrl+Shift+P --> 输入c++ --> 选中"C/C++:Edit Configurations (UI)"

    在这里插入图片描述

    修改配置 c_cpp_properties.json

    在这里插入图片描述
    在这里插入图片描述

    // c_cpp_properties.json
    {
      "configurations": [
        {
          "name": "windows-gcc-x64",
          "includePath": [
            "${workspaceFolder}/**"
          ],
          "compilerPath": "C:/tools/mingw64/bin/gcc.exe",
          "cStandard": "${default}",
          "cppStandard": "${default}",
          "intelliSenseMode": "windows-gcc-x64",
          "compilerArgs": [
            ""
          ]
        }
      ],
      "version": 4
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    6.配置构建任务

    快捷键:Ctrl+Shift+P --> 输入Task --> 选中"Tasks: Configure Default Build Task" --> 选中"C/C++: g++.exe 生成活动文件"

    在这里插入图片描述
    在这里插入图片描述

    // task.json 文件内容展示
    {
    	"version": "2.0.0",
    	"tasks": [
    		{
    			"type": "cppbuild",
    			"label": "C/C++: g++.exe 生成活动文件",
    			"command": "C:\\tools\\mingw64\\bin\\g++.exe",
    			"args": [
    				"-fdiagnostics-color=always",
    				"-g",
    				"${file}",
    				"-o",
    				"${fileDirname}\\${fileBasenameNoExtension}.exe"
    			],
    			"options": {
    				"cwd": "${fileDirname}"
    			},
    			"problemMatcher": [
    				"$gcc"
    			],
    			"group": {
    				"kind": "build",
    				"isDefault": true
    			},
    			"detail": "编译器: C:\\tools\\mingw64\\bin\\g++.exe"
    		}
    	]
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29

    7.配置调试设置

    修改调试配置文件 launch.json

    "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
    
    • 1

    调试测试 : 工具栏 “Run” --> “Start Debugging”

    // launch.json
    {
      "version": "0.2.0",
      "configurations": [
        {
          "name": "C/C++ Runner: Debug Session",
          "type": "cppdbg",
          "request": "launch",
          "args": [],
          "stopAtEntry": false,
          "externalConsole": true,
          "cwd": "d:/c语言项目/test01",
          "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
          "MIMode": "gdb",
          "miDebuggerPath": "gdb",
          "setupCommands": [
            {
              "description": "Enable pretty-printing for gdb",
              "text": "-enable-pretty-printing",
              "ignoreFailures": true
            }
          ]
        }
      ]
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
  • 相关阅读:
    数栈xAI:轻量化、专业化、模块化,四大功能革新 SQL 开发体验
    Go Mutex(互斥锁)
    HarmonyOS 自定义抽奖转盘开发(ArkTS)
    数据结构与算法--分治策略
    怎么关闭管理员权限?
    ubuntu18.04 开机后黑屏,左上角光标(强制关机后)
    刷题整理(持续更新~)
    vivado 时序约束
    Hadoop的HDFS的集群安装部署
    MyBatis框架
  • 原文地址:https://blog.csdn.net/chenliang1038/article/details/134424095