怎样让VS Code编辑C++更舒适

骑猪看日落 2024-03-16 23:16 191阅读 0赞

大家在看到这篇文章前,为了有一个舒适的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++ ,如果和下图中的一样就说明成功了。

c1be76f5aa929fae7590ca0d6d92d3e3.png

  • 下载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

  1. {
  2. "configurations": [
  3. {
  4. "name": "Win32",
  5. "includePath": [
  6. "${workspaceFolder}/**"
  7. ],
  8. "defines": [
  9. "_DEBUG",
  10. "UNICODE",
  11. "_UNICODE"
  12. ],
  13. "compilerPath": "D:\\mingw64\\bin\\gcc.exe",//这里要填你的mingw路径
  14. "cStandard": "gnu17",
  15. "cppStandard": "gnu++14",
  16. "intelliSenseMode": "windows-gcc-x64"
  17. }
  18. ],
  19. "version": 4
  20. }

2.launch.json

  1. {
  2. "version": "0.2.0",
  3. "configurations": [
  4. {
  5. "name": "C/C++ 14 (GCC 9) ",
  6. "type": "cppdbg",
  7. "request": "launch",
  8. "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
  9. "args": [],
  10. "stopAtEntry": false,
  11. "cwd": "${workspaceFolder}",
  12. "environment": [],
  13. "externalConsole": true,
  14. "MIMode": "gdb",
  15. "miDebuggerPath": "D:\\Dev-Cpp\\MinGW64\\bin\\gdb.exe",//这里要填你的mingw路径
  16. "setupCommands": [
  17. {
  18. "description": "Enable pretty-printing for gdb",
  19. "text": "-enable-pretty-printing",
  20. "ignoreFailures": true
  21. }
  22. ],
  23. "preLaunchTask": "task g++"
  24. }
  25. }

3.settings.json

  1. {
  2. "editor.cursorBlinking": "smooth",
  3. "editor.smoothScrolling": true,
  4. "editor.tabCompletion": "on",
  5. "editor.fontLigatures": true,
  6. "editor.detectIndentation": false,
  7. "editor.insertSpaces": true,
  8. "editor.copyWithSyntaxHighlighting": false,
  9. "editor.suggest.snippetsPreventQuickSuggestions": false,
  10. "editor.stickyTabStops": true,
  11. "editor.wordBasedSuggestions": false,
  12. "editor.cursorSmoothCaretAnimation": true,
  13. "terminal.integrated.defaultProfile.windows": "Command Prompt",
  14. "terminal.integrated.cursorBlinking": true,
  15. "terminal.integrated.rightClickBehavior": "default",
  16. "files.autoGuessEncoding": true,
  17. "files.autoSave": "onFocusChange",
  18. "files.exclude": {
  19. "**/.git": true,
  20. "**/.svn": true,
  21. "**/*.exe": true,
  22. "**/.hg": true,
  23. "**/CVS": true,
  24. "**/.DS_Store": true,
  25. "**/tmp": true,
  26. "**/node_modules": true,
  27. "**/bower_components": true
  28. },
  29. "files.watcherExclude": {
  30. "**/.git/objects/**": true,
  31. "**/.git/subtree-cache/**": true,
  32. "**/node_modules/**": true,
  33. "**/tmp/**": true,
  34. "**/bower_components/**": true,
  35. "**/dist/**": true
  36. },
  37. "workbench.list.smoothScrolling": true,
  38. "workbench.editor.enablePreview": false,
  39. "workbench.editor.untitled.hint": "hidden",
  40. "explorer.confirmDelete": false,
  41. "explorer.confirmDragAndDrop": false,
  42. "search.followSymlinks": false,
  43. "window.dialogStyle": "custom",
  44. "debug.showBreakpointsInOverviewRuler": true,
  45. "debug.toolBarLocation": "docked",
  46. "debug.onTaskErrors": "showErrors",
  47. "code-runner.runInTerminal": true,
  48. "code-runner.executorMap": {
  49. "cpp": " cls && cd /d $dir && g++ $fullFileName -static-libgcc -std=c++11 -fexec-charset=GBK -o \"$fileNameWithoutExt.exe\" && D:\\ConsolePauser.exe $dirWithoutTrailingSlash\\$fileNameWithoutExt.exe\"",
  50. "c": " cls && cd /d $dir && gcc $fullFileName -static-libgcc -std=c++11 -fexec-charset=GBK -o \"$fileNameWithoutExt.exe\" && D:\\ConsolePauser.exe $dirWithoutTrailingSlash\\$fileNameWithoutExt.exe\"",
  51. },
  52. "code-runner.saveFileBeforeRun": true,
  53. "code-runner.customCommand": " cls",
  54. "code-runner.respectShebang": false,
  55. "code-runner.preserveFocus": false,
  56. "editor.tokenColorCustomizations": {
  57. "comments": "#399afc",
  58. "variables": "#AAB5BB",
  59. }
  60. }

4.tasks.json

  1. {
  2. "version": "2.0.0",
  3. "tasks": [
  4. {
  5. "type": "shell",
  6. "label": "task g++",
  7. "command": "D:\\Dev-Cpp\\MinGW64\\bin\\g++.exe",//这里要填你的mingw路径
  8. "args": [
  9. "-g",
  10. "${file}",
  11. "-o",
  12. "${fileDirname}\\${fileBasenameNoExtension}.exe"
  13. ],
  14. "options": {
  15. "cwd": "D:\\Dev-Cpp\\MinGW64\\bin"//这里要填你的mingw路径
  16. },
  17. "problemMatcher": [
  18. "$gcc"
  19. ],
  20. "group": "build"
  21. },
  22. {
  23. "type": "cppbuild",
  24. "label": "C/C++: g++.exe 生成活动文件",
  25. "command": "D:\\Dev-Cpp\\MinGW64\\bin\\g++.exe",//这里要填你的mingw路径
  26. "args": [
  27. "-fdiagnostics-color=always",
  28. "-g",
  29. "${file}",
  30. "-o",
  31. "${fileDirname}\\${fileBasenameNoExtension}.exe"
  32. ],
  33. "options": {
  34. "cwd": "${fileDirname}"
  35. },
  36. "problemMatcher": [
  37. "$gcc"
  38. ],
  39. "group": {
  40. "kind": "build",
  41. "isDefault": true
  42. },
  43. "detail": "调试器生成的任务。"
  44. }
  45. ]
  46. }

然后在 .vscode 同级目录下创建文件,就可以运行啦。

效果图

b50b0e6af4425e05c22b741a85bcd13b.png

发表评论

表情:
评论列表 (有 0 条评论,191人围观)

还没有评论,来说两句吧...

相关阅读

    相关 VS Code编辑功能说明

    特别说明: 1.42.1版本是Shift键+Alt键+鼠标左键 新版本v1.13.1或者附近的版本中的列编辑功能已经调整。 一、多光标插入功能 Alt+鼠标左键,添加多

    相关 VS code运行C/C++代码

    一、VS code 非常强大的开发工具!!! 二、插件 PS:一般装有g++或者能够运行C/C++程序的电脑只需要安装下面两个插件即可正常编译运行C/C++程序。

    相关 VS Code远程编辑

    一、安装 Visual Studio Code 安装方法自行百度。 二、点击下图中箭头所指图标打开应用商店,搜索SFTP插件安装。 ![在这里插入图片描述][201