VS Code 写C或C++语言初学者配置环境总结
1. 安装vscode。
Visual Studio Code - Code Editing. Redefined 下载安装vscode.
2.安装c/c++扩展。
3.安装编译工具mingw-w64,http://www.mingw-w64.org/doku.php/download
(GCC with the MCF thread model 这个网址直接下载) ,然后配置环境变量,以WIN10为例 ,此电脑-属性-高级系统设置-环境变量-系统变量-path-添加一条D:\Program Files\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin(你安装编译工具路径)
配置前:
配置后:
-ps:如果开着vscode配置环境变量,配置完要关掉vscode重开一次。
4. 现在在本地上创建一个文件夹,作为vscode要导入的项目。
5.打开vscode,导入这个文件夹,再创建cpp文件进行编码。
6.配置文件launch.json,task.json
按F5弹出选择环境,配置launch.json
launch.json 里面内容如下(全选,复制粘贴,修改路径):
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "D:\\0xFF\\mingw-w64-gcc-mcf\\mingw64\\bin\\gdb.exe",
"preLaunchTask": "g++",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
},
]
}
7.再创建task.json文件。内容如下:
{
"version": "2.0.0",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.exe"
],
"problemMatcher": {
"owner": "cpp",
"fileLocation": [
"relative",
"${workspaceRoot}"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
},
"group": {
"kind": "build",
"isDefault": true
}
}
8.设置完以上环境。可以编写代码。直接快捷键F5运行。