每次,我点击Run and Debug,cpp文件,我会到达这个文件,"launch.json";。在youtube上没有足够的帮助,而且,我无法从VSCode官方文档中解决这个问题。
我的cpp文件
#include<iostream>
using namespace std;
int main(){
int iam;
std::cout<<"salam from Pakistan!";
cout<<endl<<"enter number";
cin>>iam;
return 0;
}
launch.json文件
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: g++.exe build active file",
"command": "C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\g++.exe",
"args": ["-g", "${file}", "-o", "${fileDirname}\${fileBasenameNoExtension}.exe"],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
此外,我不知道这个tasks.json文件是什么,我在.vscode文件夹中看到了它和launch.json。
删除当前的launch.json
,然后打开文件并转到Run
->StartDebugging
。这将指导您选择编译器和调试器,并生成launch.json文件,该文件应如下所示:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++ build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
正如您所看到的,您已经定义了task
,而不是configuration
。
tasks.json如下所示:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Generated task by Debugger"
}
],
"version": "2.0.0"
}