最近一直在用編輯器,記錄下Atom 和VS Code兩款編輯器編譯和調試C++時的注意事項,避免之後忘記了。c++
操做環境Win:git
切換至工做目錄(這裏使用一個簡單的測試目錄),使用atom打開工做目錄:shell
想要使用Atom來編譯運行C++,若文件相對較少,則能夠只安裝gpp-compiler的Atom插件便可完成編譯運行json
主要功能:編輯器
This Atom package allows you to compile and run C++ and C within the editor.ide
快捷按鍵:測試
To compile C or C++, press F5 or right click the file in tree view and click Compile and Run./按F5來編譯並運行c/c++,或者在文件目錄上右鍵選擇編譯並運行字體
To compile C or C++ and attach the GNU Debugger, press F6 or right click the file in tree view and click Compile and Debug./按F6來編譯、調試c/c++,或者在文件目錄上右鍵選擇編譯並調試ui
安裝linter & linter-gcc 以及其餘依賴插件,以後即可以在Atom中獲得語法提示、錯誤標註等幫助this
Linter plugin for Linter, provides an interface to gcc/g++.
Used with files with grammar "C", "C++" and "C++14".
Now with linting on-the-fly! This is a new feature so please open an issue if you encounter any problems.
安裝完GCC Make Run插件,就可使用make命令來執行工做目錄下的Makefile文件,是在Atom中實現多文件編譯的主要插件
主要功能:
設置選項:
可使用默認的編譯器路徑:
或者填寫本身安裝的路徑:
快捷按鍵:
運行示例:
主要功能:
快捷按鍵:
運行示例:
若是要使用Atom來完成對C++的多文件編譯運行能夠安裝:
使用Makefile方法來編譯項目的好處是可使用不一樣的編輯器來編譯和運行,即有着能夠跨平臺好處。
使用VS Code打開相同工做目錄:
在VS Code中編譯c++須要用到的插件:C/C++ for Visual Studio Code就足夠了
另外,須要編寫幾條json:
{ "configurations": [ { "name": "Win32", "includePath": [ "${workspaceFolder}/**", "${workspaceFolder}/include" //Notice1:添加include文件夾 ], "defines": [ "_DEBUG", "UNICODE", "_UNICODE" ], "compilerPath": "C:\\MinGW\\bin\\gcc.exe", //Notice2:gcc路徑 "cStandard": "c11", "cppStandard": "c++17", "intelliSenseMode": "clang-x64" } ], "version": 4 }
c_cpp_properties.json配置完成以後,直接的表現便是代碼中引入的標準頭文件下的綠色波浪線再也不顯示。
{ // 使用 IntelliSense 瞭解相關屬性。 // 懸停以查看現有屬性的描述。 // 欲瞭解更多信息,請訪問: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "type": "cppdbg", "request": "launch", "name": "Launch GDB", "program": "${workspaceFolder}/build/hello.exe", //程序路徑 "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "preLaunchTask": "build", //須要在模板中額外加入預啓動任務的label "MIMode": "gdb", "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe", //gdb路徑 "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] }, { "type": "cppdbg", "request": "launch", "name": "Launch Program Example", "program": "${workspaceFolder}/build/hello.exe", //程序路徑 "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "preLaunchTask": "build", //須要在模板中額外加入預啓動任務的label "MIMode": "gdb", "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe", //gdb路徑 "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] }, ] }
添加launch配置以後的效果:
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "build", "type": "shell", "command": "make", //表示執行make命令 "group": { "kind": "build", "isDefault": true } } ] }
運行示例:
一、註釋:
單行註釋:[ctrl+k+c] 或 ctrl+/
取消單行註釋:[ctrl+k+u] 或 ctrl+/
多行註釋:[alt+shift+A]
多行註釋:/**
二、移動行:alt+up/down
三、顯示/隱藏左側目錄欄 ctrl + b
四、複製當前行:shift + alt +up/down
五、刪除當前行:shift + ctrl + k
六、控制檯終端顯示與隱藏:ctrl + ~
七、查找文件/安裝vs code 插件地址:ctrl + p
八、代碼格式化:shift + alt + f (Before use this keyboard shortcut you need to install formatter document for the using language .)
九、新建一個窗口 : ctrl + shift + n
十、行增長縮進: ctrl + [
十一、行減小縮進: ctrl + ]
十二、裁剪尾隨空格 : ctrl + shift + x
1三、字體放大/縮小: ctrl + / -
1四、拆分編輯器 : ctrl + 1 / 2
1五、切換窗口 : ctrl + shift + left/right
1六、關閉編輯器窗口 : ctrl + w
1七、關閉全部窗口 : ctrl + k + w
1八、切換全屏 : F11
1九、自動換行 : alt + z
20、顯示git : ctrl + shift + g
2一、全局查找文件:ctrl + shift + f
2二、顯示相關插件的命令 :ctrl + shift + p
2三、選中文字:shift + left / right / up / down
2四、摺疊代碼: ctrl + k + 0
2五、展開代碼: ctrl + k + j
2六、快速切換主題:ctrl + k / ctrl + t
2七、快速回到頂部 : ctrl + home
2八、快速回到底部 : ctrl + end
2九、格式化選定代碼 :ctrl + k / ctrl +f
30、選中代碼 : shift + 鼠標左鍵
3一、多行同時添加內容 :ctrl + alt + up/down
3二、全局替換:ctrl + shift + h
3三、當前文件替換:ctrl + h
3四、打開最近打開的文件:ctrl + r
3五、打開新的命令窗:ctrl + shift + c
https://go.microsoft.com/fwlink/?linkid=830387
https://atom.io/packages/build