版本比较
vscode 配置
正文
增加 566 行删除 82 行
11 行未改动12131415161617181920212223242525262728293031323334353637383940414243444546262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816948495051525354555657581701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332346162636465666768697071727374757677787980818283848586878823523623723823924091929394959697989910010110210310410510610710824124224324424524624724824925025125225325425525625725825911026026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030111330230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659711 行未改动**方式一:手动终端编译**
打开内置终端(`` Ctrl + ` ``),使用以下命令编译运行:```bashg++ 文件名.cpp -o 文件名 -std=c++14 -O2 -Wall && ./文件名g++ 文件名.cpp -o 文件名 -std=c++14 -O2 -Wall ./文件名```
**方式二:配置 `tasks.json` 实现一键编译**
如需在 VS Code 内按快捷键编译,可创建 `.vscode/tasks.json` 文件。
```json{ "version": "2.0.0", "tasks": [ { "label": "编译 C++(评测版)", "type": "shell", "command": "g++", "args": [ "-std=c++14", "-O2", "-Wall", "-Wextra", "-g", "-Wl,--stack=1024000000", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}.exe" ], "options": { "cwd": "${fileDirname}", "shell": { "executable": "C:\\Windows\\System32\\cmd.exe", "args": ["/d", "/c"] "version": "2.0.0", "tasks": [ { "label": "编译 C++(评测版)", "type": "shell", "command": "/usr/bin/g++", "args": [ "-std=c++14", "-O2", "-Wall", "-Wextra", "-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}" ], "options": { "cwd": "${fileDirname}" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true }, "presentation": { "reveal": "silent", "panel": "shared", "clear": true } }, { "label": "编译 C++(调试版)", "type": "shell", "command": "/usr/bin/g++", "args": [ "-std=c++14", "-O0", "-g", "-Wall", "-Wextra", "-fsanitize=address,undefined", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}" ], "options": { "cwd": "${fileDirname}" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": false }, "presentation": { "reveal": "silent", "panel": "shared", "clear": true } }, { "label": "运行 C++", "type": "shell", "command": "${fileDirname}/${fileBasenameNoExtension}", "options": { "cwd": "${fileDirname}" }, "dependsOn": [ "编译 C++(评测版)" ], "dependsOrder": "sequence", "presentation": { "reveal": "always", "panel": "shared", "clear": true, "focus": true }, "problemMatcher": [] }, { "label": "仅运行 C++", "type": "shell", "command": "${fileDirname}/${fileBasenameNoExtension}", "options": { "cwd": "${fileDirname}" }, "presentation": { "reveal": "always", "panel": "shared", "clear": true, "focus": true }, "problemMatcher": [] }, { "label": "运行 Python", "type": "shell", "command": "python3", "args": [ "${file}" ], "options": { "cwd": "${fileDirname}" }, "presentation": { "reveal": "always", "panel": "shared", "clear": true, "focus": true }, "problemMatcher": [] } ]}```windows 中:
```json{ "version": "2.0.0", "tasks": [ { "label": "编译 C++(评测版)", "type": "shell", "command": "g++", "args": [ "-std=c++14", "-O2", "-Wall", "-Wextra", "-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe", "-static-libgcc", "-static-libstdc++" ], "options": { "cwd": "${fileDirname}" }, "problemMatcher": [ }, "problemMatcher": ["$gcc"], "group": { "kind": "build", "isDefault": true }, "presentation": { "reveal": "silent", "panel": "shared", "clear": true } "$gcc" ], "group": { "kind": "build", "isDefault": true }, "presentation": { "reveal": "silent", "panel": "shared", "clear": true } }, { "label": "运行 C++", "type": "shell", "command": "${fileDirname}\\${fileBasenameNoExtension}.exe", "options": { "cwd": "${fileDirname}" }, "dependsOn": [ "编译 C++(评测版)" ], "dependsOrder": "sequence", "presentation": { "reveal": "always", "panel": "shared", "clear": true, "focus": true }, "problemMatcher": [] }, { "label": "运行 Python", "type": "shell", "command": "python", "args": [ "${file}" ], "options": { "cwd": "${fileDirname}" }, "presentation": { "reveal": "always", "panel": "shared", "clear": true, "focus": true }, "problemMatcher": [] } ]}```
## 一键编译运行
`Preferences: Open Keyboard Shortcuts (JSON)`
```json[ { "key": "ctrl+shift+b", "command": "workbench.action.tasks.build", "when": "resourceLangId == cpp" }, { "label": "编译 C++(调试版)", "type": "shell", "command": "g++", "args": [ "-std=c++14", "-O0", "-g", "-Wall", "-Wextra", "-Wl,--stack=1024000000", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}.exe" ], "options": { "cwd": "${fileDirname}", "shell": { "executable": "C:\\Windows\\System32\\cmd.exe", "args": ["/d", "/c"] } }, "problemMatcher": ["$gcc"], "group": "build", "presentation": { "reveal": "silent", "panel": "shared", "clear": true } "key": "ctrl+f5", "command": "workbench.action.tasks.runTask", "args": "运行 C++", "when": "resourceLangId == cpp" }, { "label": "运行 C++", "type": "shell", "command": "${fileDirname}/${fileBasenameNoExtension}.exe", "options": { "cwd": "${fileDirname}" }, "dependsOn": ["编译 C++(评测版)"], "dependsOrder": "sequence", "group": { "kind": "test", "isDefault": true }, "presentation": { "reveal": "always", "panel": "shared", "clear": true }, "problemMatcher": [] "key": "ctrl+alt+r", "command": "workbench.action.tasks.runTask", "args": "仅运行 C++", "when": "resourceLangId == cpp" }, { "key": "ctrl+alt+p", "command": "workbench.action.tasks.runTask", "args": "运行 Python", "when": "resourceLangId == python" }, { "key": "ctrl+alt+z", "command": "glassit.increase" }, { "key": "ctrl+alt+c", "command": "glassit.decrease" } ]]```
# launch.json
```json{ "version": "0.2.0", "configurations": [ { "name": "调试 C++(开栈 512MB)", "type": "cppdbg", "request": "launch", "program": "${fileDirname}/${fileBasenameNoExtension}", "args": [], "stopAtEntry": false, "cwd": "${fileDirname}", "environment": [], "externalConsole": false, "MIMode": "gdb", "preLaunchTask": "编译 C++(调试版)", "setupCommands": [ { "description": "启用 shell 启动,使 ulimit 生效", "text": "-gdb-set startup-with-shell on", "ignoreFailures": true }, { "description": "设置栈大小为 512MB(524288 KB)", "text": "-gdb-set exec-wrapper sh -c 'ulimit -s 524288 && exec \"$@\"' --", "ignoreFailures": true }, { "description": "为 gdb 启用整齐打印", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ]}```配置后,按 `Ctrl+Shift+B` 即可编译当前文件。
# 颜色配置
`Preferences: Open User Settings (JSON)`
```json{ "vs64.showWelcome": false, "code-runner.runInTerminal": true, "editor.fontSize": 20, "cmake.showOptionsMovedNotification": false, "code-runner.executorMapByGlob": { "pom.xml": "cd $dir && mvn clean package" }, "workbench.colorTheme": "Dark Modern", "files.autoSave": "afterDelay", "editor.mouseWheelZoom": true, "editor.detectIndentation": false, "editor.insertSpaces": false, "terminal.integrated.enableMultiLinePasteWarning": "never"}```
```json{ "workbench.colorCustomizations": { "editorCursor.foreground": "#ffffff", "editorCursor.background": "#ffffff", "editor.lineHighlightBackground": "#30cfff1e", "editor.lineHighlightBorder": "#30cfff1e",
"editor.findMatchBackground": "#ffeb3b7a", "editor.findMatchBorder": "#ffeb3b7a", "editor.findMatchHighlightBackground": "#B3E5FC44", "editor.findMatchHighlightBorder": "#03A9F4",
"editorBracketHighlight.foreground1": "#fffb00cb", "editorBracketHighlight.foreground2": "#7bff00d0", "editorBracketHighlight.foreground3": "#00aeffcb", "editorBracketHighlight.foreground4": "#8c00ffc2", "editorBracketHighlight.foreground5": "#ff00aac6", "editorBracketHighlight.foreground6": "#ff8800d0", "editorBracketHighlight.unexpectedBracket.foreground": "#FF0000", "editorBracketMatch.background": "#5c5c5c", "editorBracketMatch.border": "#5c5c5c",
"terminalCursor.foreground": "#ffffff", "terminalCursor.background": "#ffffff" }}```
```json{ "vs64.showWelcome": false, "code-runner.runInTerminal": true, "editor.fontSize": 20, "editor.lineHeight": 30, "cmake.showOptionsMovedNotification": false, "code-runner.executorMapByGlob": { "pom.xml": "cd $dir && mvn clean package" }, "workbench.colorTheme": "Dark Modern", "files.autoSave": "afterDelay", "editor.mouseWheelZoom": true, "editor.detectIndentation": false, "editor.insertSpaces": false, "terminal.integrated.enableMultiLinePasteWarning": "never",
"workbench.colorCustomizations": { "activityBar.background": "#0D1117", "activityBar.foreground": "#39C5BB", "activityBar.inactiveForeground": "#484F58", "activityBarBadge.background": "#39C5BB", "activityBarBadge.foreground": "#0D1117",
"sideBar.background": "#0D1117", "sideBar.foreground": "#C9D1D9", "sideBarTitle.foreground": "#39C5BB", "sideBarSectionHeader.background": "#161B22", "sideBarSectionHeader.foreground": "#58A6FF",
"editor.background": "#0D1117", "editor.foreground": "#FFFFFF", "editorLineNumber.foreground": "#484F58", "editorLineNumber.activeForeground": "#39C5BB", "editorCursor.foreground": "#39C5BB", "editor.selectionBackground": "#39C5BB44", "editor.inactiveSelectionBackground": "#39C5BB22", "editor.lineHighlightBackground": "#161B22", "editor.findMatchBackground": "#39C5BB66", "editor.findMatchHighlightBackground": "#39C5BB44", "editorWhitespace.foreground": "#21262D", "editorIndentGuide.background1": "#21262D", "editorIndentGuide.activeBackground1": "#39C5BB", "editorBracketMatch.background": "#39C5BB33", "editorBracketMatch.border": "#39C5BB", "editorGutter.background": "#0D1117", "editorGroup.border": "#21262D", "editorOverviewRuler.border": "#21262D", "editorError.foreground": "#F85149", "editorWarning.foreground": "#D29922", "editorInfo.foreground": "#39C5BB", "editorHint.foreground": "#39C5BB",
"statusBar.background": "#0A192F", "statusBar.foreground": "#FFFFFF", "statusBar.noFolderBackground": "#0D1117", "statusBar.debuggingBackground": "#39C5BB", "statusBar.debuggingForeground": "#0A192F",
"tab.activeBackground": "#0D1117", "tab.activeForeground": "#FFFFFF", "tab.inactiveBackground": "#0D1117", "tab.inactiveForeground": "#5A8A9A", "tab.border": "#161B22", "tab.activeBorderTop": "#39C5BB",
"panel.background": "#0D1117", "panel.border": "#21262D", "panelTitle.activeForeground": "#39C5BB", "panelTitle.inactiveForeground": "#484F58",
"terminal.background": "#0D1117", "terminal.foreground": "#FFFFFF", "terminal.ansiBlack": "#0D1117", "terminal.ansiRed": "#F85149", "terminal.ansiGreen": "#39C5BB", "terminal.ansiYellow": "#D29922", "terminal.ansiBlue": "#58A6FF", "terminal.ansiMagenta": "#BC8CFF", "terminal.ansiCyan": "#39C5BB", "terminal.ansiWhite": "#FFFFFF", "terminal.ansiBrightBlack": "#484F58", "terminal.ansiBrightRed": "#FF7B72", "terminal.ansiBrightGreen": "#39C5BB", "terminal.ansiBrightYellow": "#E3B341", "terminal.ansiBrightBlue": "#79C0FF", "terminal.ansiBrightMagenta": "#D2A8FF", "terminal.ansiBrightCyan": "#39C5BB", "terminal.ansiBrightWhite": "#FFFFFF",
"button.background": "#39C5BB", "button.foreground": "#0A192F", "button.hoverBackground": "#4DB6AC",
"input.background": "#161B22", "input.foreground": "#FFFFFF", "input.border": "#21262D", "inputOption.activeBorder": "#39C5BB",
"dropdown.background": "#161B22", "dropdown.foreground": "#FFFFFF", "dropdown.border": "#21262D",
"list.activeSelectionBackground": "#39C5BB33", "list.activeSelectionForeground": "#FFFFFF", "list.hoverBackground": "#161B22", "list.highlightForeground": "#39C5BB",
"scrollbarSlider.background": "#39C5BB33", "scrollbarSlider.hoverBackground": "#39C5BB55", "scrollbarSlider.activeBackground": "#39C5BB88",
"badge.background": "#39C5BB", "badge.foreground": "#0A192F", "progressBar.background": "#39C5BB",
"editorWidget.background": "#161B22", "editorWidget.border": "#21262D", "editorSuggestWidget.background": "#161B22", "editorSuggestWidget.border": "#21262D", "editorSuggestWidget.selectedBackground": "#39C5BB33", "editorHoverWidget.background": "#161B22", "editorHoverWidget.border": "#21262D",
"peekView.border": "#39C5BB", "peekViewEditor.background": "#0D1117", "peekViewResult.background": "#0D1117",
"gitDecoration.addedResourceForeground": "#39C5BB", "gitDecoration.modifiedResourceForeground": "#58A6FF", "gitDecoration.deletedResourceForeground": "#F85149", "gitDecoration.untrackedResourceForeground": "#39C5BB", "gitDecoration.ignoredResourceForeground": "#484F58" },
"editor.tokenColorCustomizations": { "comments": "#5A7A8A", "strings": "#80CBC4", "keywords": "#26C6DA", "numbers": "#4DD0E1", "types": "#80DEEA", "functions": "#00BFA5", "variables": "#FFFFFF",
"textMateRules": [ { "scope": ["comment", "punctuation.definition.comment"], "settings": { "foreground": "#5A7A8A", "fontStyle": "italic" } }, { "scope": ["string", "punctuation.definition.string"], "settings": { "foreground": "#80CBC4" } }, { "scope": ["keyword", "storage.type", "storage.modifier"], "settings": { "foreground": "#26C6DA", "fontStyle": "bold" } }, { "scope": ["entity.name.function", "support.function"], "settings": { "foreground": "#00BFA5" } }, { "scope": ["variable", "variable.parameter"], "settings": { "foreground": "#FFFFFF" } }, { "scope": ["constant.numeric", "constant.language"], "settings": { "foreground": "#4DD0E1" } }, { "scope": ["entity.name.type", "support.type", "support.class", "storage.type"], "settings": { "foreground": "#80DEEA" } }, { "scope": ["constant.other", "variable.language"], "settings": { "foreground": "#00BCD4" } }, { "scope": ["keyword.operator"], "settings": { "foreground": "#6A8A9A" } }, { "scope": ["punctuation", "meta.brace"], "settings": { "foreground": "#6A8A9A" } }, { "scope": ["markup.heading"], "settings": { "foreground": "#26C6DA", "fontStyle": "bold" } }, { "scope": ["markup.bold"], "settings": { "fontStyle": "bold" } }, { "scope": ["markup.italic"], "settings": { "fontStyle": "italic" } } ] }, "background.enabled": true, "background.editor": { "images": [ "/usr/share/backgrounds/vscode-bg.jpg" ], "useFront": false, "style": { "background-position": "center center", "background-size": "cover", "opacity": 0.08, "background-repeat": "no-repeat" } }}```