Sublime Text 配置成 C++ IDE

來源:互聯網
上載者:User

標籤:輸入資料   完整   row   ram   too   get   ctr   檔案夾   packages   

在Windows中將Sublime Text配置成C++的IDE。
首先,為了運行C++需要安裝g++編譯器,g++可直接在codeblocks中找到。
codeblock的官網是http://www.codeblocks.org/downloads/26。
大家可以下載一個較全的codeblock進行編程,地址是http://sourceforge.net/projects/codeblocks/files/Binaries/16.01/Windows/codeblocks-16.01mingw_fortran-setup.exe。
不過大家也可以直接mingw,再去其環境中找到g++編譯器。

安裝完codeblocks之後,可以在安裝目錄中找到MinGW\bin這個檔案夾。

接著在Sublime Text中的Tools中的Build System中找到New Build System,

在新開啟的檔案中編輯(命名為cplusplus.sublime-build):

{"path": "D:/Program Files (x86)/CodeBlocks/MinGW/bin","shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\"","file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$","working_dir": "${file_path}","selector": "source.c, source.c++","variants":[{"name": "Run","shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\" < input.txt > output.txt"}]}

命名成cplusplus.sublime-build儲存在User目錄裡。

這裡解釋一下上面一些欄位的意思,該檔案其實是一個JSON檔案。

在*.sublime-build* 中包括如下構建系統變數。

$file_path 當前檔案所在路徑, 比如 C:\Files.
$file 當前檔案的完整路徑, 比如 C:\Files\Chapter1.txt.
$file_name 當前檔案的檔案名稱, 比如 Chapter1.txt.
$file_extension 當前檔案的副檔名, 比如 txt.
$file_base_name 當前檔案僅包含檔案名稱的部分, 比如 Document.
$packages Packages 檔案夾的完整路徑.
$project 當前專案檔的完整路徑.
$project_path 當前專案檔的路徑.
$project_name 當前專案檔的名稱.
$project_extension 當前專案檔的擴充部分.
$project_base_name 當前項目僅包括名的部分.

更多介紹可以看:http://sublimetext.info/docs/en/reference/build_systems.html

接著就可以在Sublime Text中的Tools中的Build System中看到cplusplus,

編寫test.cpp測試程式,並在同一目錄下,建立兩個檔案:input.txt 和 output.txt 。

之後在input.txt輸入輸入資料,用快速鍵Ctrl+Shift+B(或者在Tools下選擇Build With...)就可以看到

選擇第一個則只是編譯test.cpp,選擇第二個則可以編譯並運行程式,在output.txt中看到結果。

是不是很方便呢??

Sublime Text 配置成 C++ IDE

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.