之所以会写这段随笔,是因为我的vscode,配置c++环境之后,尝试了在程序后面加 getchar() system("pause")后都没有用最终还是通过修改c++编辑文件 launch.json,以及 tasks.json
,其中要注意,如果多次配置不成功还是失败,其一,可以试试吧 launch.json的“profram”修改一下后面的”.exe“去掉
"program": "${workspaceFolder}/${fileBasenameNoExtension}",// 将要进行调试的程序的路径
其二将launch.json里的args可以修改一下
"args": [
"/k",
"${fileDirname}\${fileBasenameNoExtension}.exe",
],
也可以改为 "/C", "${fileDirname}/${fileBasenameNoExtension}.exe", "&", "pause"
话不多说直接上代码
1.launch.json
1 { 2 "version": "0.2.0", 3 "configurations": [ 4 5 { 6 "name": "(Windows) Launch", 7 "type": "cppvsdbg", 8 "request": "launch", 9 "program": "cmd", 10 "args": [ 11 "/k", 12 "${fileDirname}\${fileBasenameNoExtension}.exe", 13 ], 14 "stopAtEntry": false, 15 "cwd": "${workspaceFolder}", 16 "environment": [], 17 "externalConsole":true 18 }, 19 //"igurations": [ 20 { 21 "name": "(gdb) Launch", // 配置名称,将会在启动配置的下拉菜单中显示 22 "type": "cppdbg", // 配置类型,这里只能为cppdbg 23 "request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加) 24 "program": "${workspaceFolder}/${fileBasenameNoExtension}",// 将要进行调试的程序的路径 25 "args": [], // 程序调试时传递给程序的命令行参数,一般设为空即可 26 "stopAtEntry": false, // 设为true时程序将暂停在程序入口处,一般设置为false 27 "cwd": "${workspaceFolder}", // 调试程序时的工作目录,一般为${workspaceFolder}即代码所在目录 28 "environment": [], 29 "externalConsole": true, // 调试时是否显示控制台窗口,一般设置为true显示控制台 30 "MIMode": "gdb", 31 "miDebuggerPath": "E:\MinGW\bin\g++.exe", // miDebugger的路径,注意这里要与MinGw的路径对应 32 "preLaunchTask": "g++", // 调试会话开始前执行的任务,一般为编译程序,c++为g++, c为gcc 33 "setupCommands": [ 34 { 35 "description": "Enable pretty-printing for gdb", 36 "text": "-enable-pretty-printing", 37 "ignoreFailures": true 38 } 39 ] 40 } 41 ] 42 }
2.tasks.json
{ "tasks": [ { "type": "shell", "label": "g++", "command": "E:\MinGW\bin\g++.exe", "args": [ "-g", "${file}", "-o", "${fileDirname}\${fileBasenameNoExtension}.exe" ], "options": { "cwd": "E:\MinGW\bin" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true }, "detail": "Generated task by Debugger" }, { "type": "cppbuild", "label": "C/C++: cpp.exe build active file", "command": "E:\MinGW\bin\cpp.exe", "args": [ "-g", "${file}", "-o", "${fileDirname}\${fileBasenameNoExtension}.exe" ], "options": { "cwd": "E:\MinGW\bin" }, "problemMatcher": [ "$gcc" ], "group": "build", "detail": "compiler: E:\MinGW\bin\cpp.exe" }, { "type": "cppbuild", "label": "C/C++: g++.exe build active file", "command": "E:\MinGW\bin\g++.exe", "args": [ "-g", "${file}", "-o", "${fileDirname}\${fileBasenameNoExtension}.exe" ], "options": { "cwd": "E:\MinGW\bin" }, "problemMatcher": [ "$gcc" ], "group": "build", "detail": "compiler: E:\MinGW\bin\g++.exe" } ], "version": "2.0.0" }
欢迎补充!