怎样让VS Code编辑C++更舒适
大家在看到这篇文章前,为了有一个舒适的c++IDE,一定感受到了Dev-c++的廉价感,Clion功能的多余,VS的臃肿。他们也有自己的优点,但糟点太多,令人十分难受。而VS Code,可以取长补短。下面的配置内容,可以让你在刷题时,享受丝滑的动画,体会集成终端的方便,让你觉得Coding不再枯燥。
成都创新互联公司是一家集网站建设,华龙企业网站建设,华龙品牌网站建设,网站定制,华龙网站建设报价,网络营销,网络优化,华龙网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。
Step 1
下载
- 下载VS Code
方法一:前往官网选择适合的版本。(官网下载速度可能很慢)
方法二:快速下载链接。
- 安装环境
方法一:去官网下载,具体方法自行百度。
方法二:在Dev-c++的目录下找到 C:\Program Files (x86)\Dev-Cpp\MinGW64\bin
。(可以把其他文件夹删掉,这个要留下,里面的内容和方法一安装后一样,适合懒人)
在桌面上右键此电脑,属性->高级系统设置->环境变量->Path->编辑->新建
然后把 bin
文件夹的路径复制进去,保存。
然后打开cmd,输入 g++
,如果和下图中的一样就说明成功了。
- 下载ConsolePauser
点击链接下载,这个程序可以让我们在终端运行完后自动停止,并显示时间。
Step 2
配置
- 下载插件
在插件那一栏里搜索以下几个插件:
必备:
1.Chinese。(中文插件)
2.C/C++。(代码补全、语法错误等)
3.Code Runner。(像Clion一样运行程序)
可以装:
1.One Dark Pro。(好看的代码高亮)
2.vscode-icons。(好看的图标)
- 配置文件
在编辑器中打开一个文件夹,然后新建一个文件夹,名为 .vscode
。在这个文件夹里创建以下四个文件,并把内容复制进去:
1.c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "D:\\mingw64\\bin\\gcc.exe",//这里要填你的mingw路径
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}
2.launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ 14 (GCC 9) ",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "D:\\Dev-Cpp\\MinGW64\\bin\\gdb.exe",//这里要填你的mingw路径
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "task g++"
}
}
3.settings.json
{
"editor.cursorBlinking": "smooth",
"editor.smoothScrolling": true,
"editor.tabCompletion": "on",
"editor.fontLigatures": true,
"editor.detectIndentation": false,
"editor.insertSpaces": true,
"editor.copyWithSyntaxHighlighting": false,
"editor.suggest.snippetsPreventQuickSuggestions": false,
"editor.stickyTabStops": true,
"editor.wordBasedSuggestions": false,
"editor.cursorSmoothCaretAnimation": true,
"terminal.integrated.defaultProfile.windows": "Command Prompt",
"terminal.integrated.cursorBlinking": true,
"terminal.integrated.rightClickBehavior": "default",
"files.autoGuessEncoding": true,
"files.autoSave": "onFocusChange",
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/*.exe": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/tmp": true,
"**/node_modules": true,
"**/bower_components": true
},
"files.watcherExclude": {
"**/.git/objects/**": true,
"**/.git/subtree-cache/**": true,
"**/node_modules/**": true,
"**/tmp/**": true,
"**/bower_components/**": true,
"**/dist/**": true
},
"workbench.list.smoothScrolling": true,
"workbench.editor.enablePreview": false,
"workbench.editor.untitled.hint": "hidden",
"explorer.confirmDelete": false,
"explorer.confirmDragAndDrop": false,
"search.followSymlinks": false,
"window.dialogStyle": "custom",
"debug.showBreakpointsInOverviewRuler": true,
"debug.toolBarLocation": "docked",
"debug.onTaskErrors": "showErrors",
"code-runner.runInTerminal": true,
"code-runner.executorMap": {
"cpp": " cls && cd /d $dir && g++ $fullFileName -static-libgcc -std=c++11 -fexec-charset=GBK -o \"$fileNameWithoutExt.exe\" && D:\\ConsolePauser.exe $dirWithoutTrailingSlash\\$fileNameWithoutExt.exe\"",
"c": " cls && cd /d $dir && gcc $fullFileName -static-libgcc -std=c++11 -fexec-charset=GBK -o \"$fileNameWithoutExt.exe\" && D:\\ConsolePauser.exe $dirWithoutTrailingSlash\\$fileNameWithoutExt.exe\"",
},
"code-runner.saveFileBeforeRun": true,
"code-runner.customCommand": " cls",
"code-runner.respectShebang": false,
"code-runner.preserveFocus": false,
"editor.tokenColorCustomizations": {
"comments": "#399afc",
"variables": "#AAB5BB",
}
}
4.tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "task g++",
"command": "D:\\Dev-Cpp\\MinGW64\\bin\\g++.exe",//这里要填你的mingw路径
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:\\Dev-Cpp\\MinGW64\\bin"//这里要填你的mingw路径
},
"problemMatcher": [
"$gcc"
],
"group": "build"
},
{
"type": "cppbuild",
"label": "C/C++: g++.exe 生成活动文件",
"command": "D:\\Dev-Cpp\\MinGW64\\bin\\g++.exe",//这里要填你的mingw路径
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
]
}
然后在 .vscode
同级目录下创建文件,就可以运行啦。
效果图
本文标题:怎样让VS Code编辑C++更舒适
文章链接:http://pwwzsj.com/article/dsoiiej.html