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
        }
      ]
    }
  ]
}
相关推荐
Paddi93038 分钟前
Codeforces Round 1004 (Div. 1) C. Bitwise Slides
c++·算法
流星白龙5 小时前
【C++】36.C++IO流
开发语言·c++
靡不有初1116 小时前
CCF-CSP第31次认证第二题——坐标变换(其二)【NA!前缀和思想的细节,输出为0的常见原因】
c++·学习·ccfcsp
艾斯比的日常8 小时前
VSCode 实用快捷键
ide·vscode·编辑器
Galaxy_12298 小时前
vscode远程报错:Remote host key has changed,...
ide·vscode·编辑器
彬sir哥8 小时前
VScode运行后出现黑窗口
vscode·运行·黑窗口
YH_DevJourney8 小时前
Linux-C/C++《C/7、字符串处理》(字符串输入/输出、C 库中提供的字符串处理函数、正则表达式等)
linux·c语言·c++
就爱学编程8 小时前
C语言预编译
c语言·开发语言
和光同尘@9 小时前
1011. A+B和C (15)-PAT乙级真题
c语言·开发语言·数据结构·c++·算法
xianwu54310 小时前
反向代理模块kd
开发语言·网络·数据库·c++·mysql