写份心得记录一下给 vs code配置c++环境的细节

it2023-05-01  74

写份心得记录一下给 vs code配置c++环境的细节

弄了近一天,终于配置成功了,安装下载啥的其他博客都能找到,关键是这两个文件的配置。 其他步骤可以参考这个:Visual Studio Code (vscode) 配置 C / C++ 环境

1、tasks.json 配置文件 ctrl+shift+p,选择任务:配置默认生成任务,按模板配置,把下面代码复制粘贴,代替已有的模板,修改两处路径。 我的代码如下

{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "g++.exe build active file",//提醒1,记住这个标签 "command": "C:/gongzuoruanjian/mingw64/bin/g++.exe",//提醒2路径 "type": "shell", "args": [ "-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe"//提醒3,记住这个名字 ], "options": { "cwd": "C:/gongzuoruanjian/mingw64/bin"//提醒4路径 }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true } } ] }

2、 launch.json 配置文件 按f5调试,选择 C++(GDB/LLDB),把下面代码复制粘贴,代替已有的模板,按上面注释修改。

{ // 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。 // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "(gdb) 启动", "preLaunchTask": "g++.exe build active file",//对应上面提醒一,label "type": "cppdbg", "request": "launch", "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",//对应提醒三 "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true,//外部终端 "MIMode": "gdb", "miDebuggerPath": "C:/gongzuoruanjian/mingw64/bin/gdb.exe",//提醒路径 "setupCommands": [ { "description": "为 gdb 启用整齐打印", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] }

3、配置UI 按住 ctrl+shift+p ,选择编辑配置UI,按下图修改。 4、运行一个冒泡排序 程序如下,C++ 扩展是 .cpp。

#include <iostream> using namespace std; int main() { int arr[9] = { 4,2,8,0,5,7,1,3,9 }; for (int i = 0; i < 9 - 1; i++) { for (int j = 0; j < 9 - 1 - i; j++) { if (arr[j] > arr[j + 1]) { int temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; } } } for (int i = 0; i < 9; i++) { cout << arr[i] << endl; } system("pause"); return 0; }

一个是内部终端输出,一个是外部输出。

最新回复(0)