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

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

1.创建项目目录

powershell 复制代码
d:\>mkdir d:\c语言项目\test01

2.vscode打开项目目录

3.项目中添加文件

4.文件内容

cpp 复制代码
#include <iostream>
using namespace std;

int main(){
    cout << "hello world" << endl;
    return 0;
}

5.配置编译器

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

修改配置 c_cpp_properties.json


cpp 复制代码
// 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
}

6.配置构建任务

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


cpp 复制代码
// 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"
		}
	]
}

7.配置调试设置

修改调试配置文件 launch.json

cpp 复制代码
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",

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

cpp 复制代码
// 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
        }
      ]
    }
  ]
}
相关推荐
会周易的程序员几秒前
aiDgeScanner 工业设备网络扫描与管理工具
网络·c++·物联网·架构·electron·node.js·iot
叼烟扛炮13 分钟前
C++ 知识点17 友元
开发语言·c++·算法·友员
计算机安禾21 分钟前
【c++面向对象编程】第2篇:类与对象(一):定义第一个类——成员变量与成员函数
开发语言·c++
richard_yuu30 分钟前
数据结构|二叉树高阶进阶-经典算法
数据结构·c++·算法
兩尛1 小时前
c++知识点5
开发语言·c++
澈2071 小时前
C++内存管理:new/delete与内存泄漏实战
开发语言·c++·内存分区
星星码️1 小时前
LeetCode刷题简单篇之反转字母
c++·算法·leetcode
其实防守也摸鱼1 小时前
VS code怎么使用 Conda 安装预编译包
开发语言·网络·c++·vscode·安全·web安全·conda
SilentSamsara1 小时前
生成器实战:处理大文件、流水线模式与无限序列
vscode·python·青少年编程·pycharm
Hello.Reader1 小时前
ds4.c 深度解析为 DeepSeek V4 Flash 打造的本地推理引擎
c语言·开发语言