vscode寫c語言(windows)
用vscode學習c語言。
記錄vscode配置c語言編譯環境。
1.安裝vscode(版本1.27)
https://code.visualstudio.com/ 下載安裝vscode.
2.安裝c/c++擴展。
3.安裝mingw-w64,http://www.mingw-w64.org/doku.php/download
4.配置文件launch.json,task.json。
新建文件hello.cpp,
按F5彈出選擇環境,配置launch.json
點擊進去,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彈出報錯框,選配置任務。
點擊,然後這裡選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。成功運行編譯。
5.還有就是發現中文控制台顯示亂碼,
只要點擊右下角utf-8,
點使用編碼保存,選GBK,然後F5運行
※基於 Python 自建分散式高並發 RPC 服務
※程序員成熟的標誌,八個點概括!
TAG:程序員小新人學習 |