iT邦幫忙

5

[VSCode] Visual Studio Code 執行 C++ (4) - 範本 (Template)

記得以前在用 Dev C++ 時可以去設定程式範本,在新增檔案時會自動帶入範本內容,可以省去每次都要去舊檔案複製貼上的動作,這是我最常用的範本,有一個 main 函數和幾個常用的 include。
http://ithelp.ithome.com.tw/upload/images/20171004/201068655wS6DBPhaM.jpg

接下來介紹一個用來產生程式範本的套件 Template Generator。

1. 安裝 Template Generator
http://ithelp.ithome.com.tw/upload/images/20171004/20106865W9DOmUY4zr.jpg
安裝完後需重新載入套件,不然會找不到 templates 資料夾。

2. 找到 templates 資料夾放入範本
http://ithelp.ithome.com.tw/upload/images/20171004/20106865JJc6rsE9v2.jpg
C:\Users\aaa\.vscode\templates 資料夾路徑內的 aaa 是我的電腦使用者名稱,找到資料夾後新增 {__name__.cpp}.cpp 檔案,裡面放入自己的範本內容。

#include <stdio.h>
#include <stdlib.h>

int main(void)
{

    system("pause");
    return 0;
}

3. 新增檔案
http://ithelp.ithome.com.tw/upload/images/20171004/20106865Vake8zda26.jpg
快速鍵 Ctrl + Shift + P 找到 Files: New File From Template,或可以直接 Ctrl + Alt + N,然後 按 Enter

http://ithelp.ithome.com.tw/upload/images/20171004/2010686514Ig5i6TqV.jpg
可以看到剛剛新增的 cpp 範本,選擇 cpp 後按 Enter

http://ithelp.ithome.com.tw/upload/images/20171004/20106865AdlLSj8YIb.jpg
接著輸入新檔案的檔案名稱,然後按 Enter

http://ithelp.ithome.com.tw/upload/images/20171004/20106865S5hT5qzODK.jpg
成功新增檔案並且帶入範本內容 XD。

結語:
此範本套件很靈活,可以設定多個範本檔或範本資料夾,配合快速鍵真的非常好用。

相關文章:
[VSCode] Visual Studio Code 執行 C++ (1) - 安裝 VSCode + MinGW
[VSCode] Visual Studio Code 執行 C++ (2) - IntelliSense + Building + Debugging
[VSCode] Visual Studio Code 執行 C++ (3) - 語法檢查
[VSCode] Visual Studio Code 執行 C++ (4) - 範本 (Template)
[VSCode] Visual Studio Code 執行 C++ (5) - 中文亂碼
[VSCode] Visual Studio Code 執行 C++ (6) - Code Runner


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言