當前位置:
首頁 > 知識 > vscode寫c語言(windows)

vscode寫c語言(windows)

用vscode學習c語言。

記錄vscode配置c語言編譯環境。

1.安裝vscode(版本1.27)

https://code.visualstudio.com/ 下載安裝vscode.

2.安裝c/c++擴展。

vscode寫c語言(windows)

3.安裝mingw-w64,http://www.mingw-w64.org/doku.php/download

4.配置文件launch.json,task.json。

新建文件hello.cpp,

vscode寫c語言(windows)

按F5彈出選擇環境,配置launch.json

vscode寫c語言(windows)

點擊進去,configurations:里內容如下;

{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "enter program name, for example ${workspaceFolder}/a.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "/path/to/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}

修改成如下;

{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/a.exe",//這裡刪除前面那裡的enter program name, for example
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "D:\Program Files\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin\gdb.exe",//修改為你安裝mingw32的路徑
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "build hello",//task.json裡面的名字
}

回到hello.cpp按F5彈出報錯框,選配置任務。

vscode寫c語言(windows)

vscode寫c語言(windows)

點擊,然後這裡選Others,出現task.json,如下;

"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "echo Hello"
}
]

修改如下;

"version": "2.0.0",
"tasks": [
{
"label": "build hello",
"type": "shell",
"command": "g++",
"args": [
"-g", "hello.cpp",
],
"group":{
"kind": "build",
"isDefault": true
}
}
]

回到hello.cpp文件,按F5。成功運行編譯。

vscode寫c語言(windows)

5.還有就是發現中文控制台顯示亂碼,

vscode寫c語言(windows)

只要點擊右下角utf-8,

vscode寫c語言(windows)

點使用編碼保存,選GBK,然後F5運行

vscode寫c語言(windows)

喜歡這篇文章嗎?立刻分享出去讓更多人知道吧!

本站內容充實豐富,博大精深,小編精選每日熱門資訊,隨時更新,點擊「搶先收到最新資訊」瀏覽吧!


請您繼續閱讀更多來自 程序員小新人學習 的精彩文章:

基於 Python 自建分散式高並發 RPC 服務
程序員成熟的標誌,八個點概括!

TAG:程序員小新人學習 |