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
        }
      ]
    }
  ]
}
相关推荐
小林C语言3 小时前
C语言 | 判断是否为回文数
c语言
2301_803554524 小时前
c++中的绑定器
开发语言·c++·算法
海棠蚀omo4 小时前
C++笔记-位图和布隆过滤器
开发语言·c++·笔记
消失的旧时光-19435 小时前
c++ 的标准库 --- std::
c++·jni
GiraKoo5 小时前
【GiraKoo】C++11的新特性
c++·后端
不午睡的探索者5 小时前
告别性能瓶颈!Python 量化工程师,进击 C++ 高性能量化交易的“必修课”!
c++·github
OpenC++5 小时前
【C++】观察者模式
c++·观察者模式·设计模式
老歌老听老掉牙5 小时前
粒子群优化算法实现与多维函数优化应用
c++·pso·粒子群算法
myloveasuka6 小时前
信号操作集函数
linux·运维·服务器·c语言·c++·vscode
山野万里__6 小时前
C++与Java内存共享技术:跨平台与跨语言实现指南
android·java·c++·笔记