1.安装MinGw
2.配置环境变量
3.csvode中下载cpp插件
4.按f5配置launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"preLaunchTask": "Build",
"type": "cppdbg",
"request": "launch",
"targetArchitecture": "x86_64",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",
"miDebuggerPath": "c:\\MinGW\\bin\\gdb.exe",(同志!这里改你的路径,不能用我的路径)
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
5.配置tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
},
"windows": {
"command": "g++",
"args": [
"-ggdb",
"\"${file}\"",
"--std=c++11",
"-o",
"\"${fileDirname}\\${fileBasenameNoExtension}.exe\"",
]
}
}
]
}
以上步骤是完全正确的,我强调一遍!
但是vscode它就是爆粗了,啊不,报错了:
1.unrecognized command line option “-std=c++11
2.no iconv implementation,cannot convert from UTF-8 to GBK
好好好,我们来一一解决
发现task.json中
看看看看,我要用C语言环境,这里必须要改成
"windows": {
"command": "gcc",
"args": [
"-ggdb",
"\"${file}\"",
"--std=c99",
"-o",
"\"${fileDirname}\\${fileBasenameNoExtension}.exe\"",
]
}
哎,c++11不行,咱用c99嘛
还是刚刚那段,加两句(两行/中间的两句)
"windows": {
"command": "gcc",
"args": [
"-ggdb",
"\"${file}\"",
"--std=c99",
"-o",
"\"${fileDirname}\\${fileBasenameNoExtension}.exe\"",
"-finput-charset=UTF-8",//输入编译器文本编码 默认为UTF-8
"-fexec-charset=UTF-8"//编译器输出文本编码 自行选择
]
}
(一闪而过的话,别忘了加getchar();啊!)