看了教程搞了好久
总结一下就是
一.安装编译器mingw并添加环境变量
二.下载vscode并装拓展
三.配置.json文件
下面两个教程很好
上面这个教程我安装了code runner插件,结果不是黑窗口,一直是终端。后来卸载了这个插件就好了
这个问题看了很多博客,这篇终于可以了,不用加system和getchar这些
其中三个文件是这么设置的
注意我的文件目录是放在D盘
D:\\mingw64\\bin\\g++.exe
类似这样
以下的代码中涉及文件目录的地方都要改成自己电脑的文件目录
c_cpp_properties
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"D:/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/**",
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}
launch
{
"version": "0.2.0",
"configurations": [
{
"name": "编译并运行",
"type": "cppvsdbg",
"request": "launch",
"program": "cmd",
"args": [
"/C",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"&",
"pause"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "externalTerminal",
"internalConsoleOptions": "neverOpen",
"preLaunchTask": "task g++"
},
{
"name": "g++.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "D:\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "task g++"
}
]
}
tasks
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "task g++", //修改此项
"command": "D:\\mingw64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:\\mingw64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
}
]
}
运行时有两种模式,一种时黑窗口(不闪退) 一种是在终端(在最底下的窗口输入输出)
最左边点从下往上第二个,然后这个选这个模式
第一个就是黑窗口,第二个是终端