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
        }
      ]
    }
  ]
}
相关推荐
zh_xuan2 小时前
c++ 单例模式
开发语言·c++·单例模式
apocelipes3 小时前
Linux c 运行时获取动态库所在路径
linux·c语言·linux编程
int型码农4 小时前
数据结构第八章(一) 插入排序
c语言·数据结构·算法·排序算法·希尔排序
利刃大大4 小时前
【在线五子棋对战】二、websocket && 服务器搭建
服务器·c++·websocket·网络协议·项目
喜欢吃燃面4 小时前
C++刷题:日期模拟(1)
c++·学习·算法
SHERlocked934 小时前
CPP 从 0 到 1 完成一个支持 future/promise 的 Windows 异步串口通信库
c++·算法·promise
虚拟之5 小时前
36、stringstream
c++
我很好我还能学5 小时前
【面试篇 9】c++生成可执行文件的四个步骤、悬挂指针、define和const区别、c++定义和声明、将引用作为返回值的好处、类的四个缺省函数
开发语言·c++
学习噢学个屁6 小时前
基于STM32语音识别柔光台灯
c语言·stm32·单片机·嵌入式硬件·语音识别
南岩亦凛汀7 小时前
在Linux下使用wxWidgets进行跨平台GUI开发
c++·跨平台·gui·开源框架·工程实战教程