本文主要针对使用 c + + c++ c++的 O I e r OIer OIer(因为其他东西我都没学),有很多东西走了弯路,希望能以微薄的力量帮助大家学习.
本人主要学习来源:
https://www.luogu.org/blog/GNAQ/VSC-guide
https://www.luogu.com.cn/blog/crab-in-northeast/great-features-and-plugins-for-vscode
请先阅读以上内容.
下面介绍流程:
bin
添加到path
系统变量内.Ctrl +shift + p
,查找,以下简称find
.F5
,debugCtrl+Alt+n
,运行compile run
.打开文件夹后,会自动生成一个.vscode
的文件夹,内置launch.json,tasks.json...
(tasks.json主要负责编译,launch.json主要负责调试,里面有很多配置环境设置)
直接复制我的 t a s k s . j s o n : tasks.json: tasks.json:(命令行参数可以自行调整)
{
"version": "2.0.0",
"tasks": [
{
"label": "Compile",//标签(类似函数名),vscode的注释是不影响使用的哦
"command": "g++",
"args": ["-g","${file}", "-o", "${fileBasenameNoExtension}.exe","-Wall","-static-libgcc","-Wl,--stack=1000000000","-std=c++11"],//命令行参数
},
{
"label": "CompileO2",
"command": "g++",
"args": ["-g","${file}", "-o", "${fileBasenameNoExtension}.exe", "-O2","-Wall","-static-libgcc","-Wl,--stack=1000000000","-std=c++11"],
}
]
}
l a u n c h . j s o n : launch.json: launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "G++ (with O2)",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files (x86)\\Dev-Cpp\\MinGW64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": false
}
],
"preLaunchTask": "CompileO2"
},
{
"name": "G++",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files (x86)\\Dev-Cpp\\MinGW64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": false
}
],
"preLaunchTask": "Compile"
}
]
}
注意:miDebuggerPath
要设为系统的gdb.exe
的绝对路径,斜杠要两条(’//’)
如果你是js
神仙,你直接find:settings(json)
即可进行修改设置.
但是如果是小白,那么可以去设置界面查找合适自己的选项.
比如:如果你想修改compile run
的对c++
的编译指令,那么可以在设置搜索executorMap
,对cpp
的命令.
我的设置为"cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt -std=c++14 -static-libgcc -Wall -Wextra && $dir$fileNameWithoutExt",
(中间位置其实可以自由选择)
调试代码时和Dev-c++类似,设置断点,然后在 监测 内输入表达是即可查找.
最后再分享几个比较有用的插件:
C++ Intellisense
Settings Sync
TabOut
现在你就成功入坑了vscode,你可以在 插件,快捷键,js 方面涉猎更多知识,以更方便的使用vscode.