解决vscode在编译c++时报错“The PrelaunchTask ‘g++‘ terminated with exit code 1“

如果你的配置文件task.json文件是这么写的话

{
    "version": "2.0.0",
    "command": "g++",
    "args": [
        "-g",
        "${file}",
        "-o",
        "${fileDirname}/build/${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
    }
}

其中有这么一行"${fileDirname}/build/${fileBasenameNoExtension}.exe", // 指定输出文件名,将生成的.exe文件输出到build文件夹.

问题的解决

在当前.cpp文件目录下,新建一个build文件夹,就可以正常编译了.
解决vscode在编译c++时报错“The PrelaunchTask ‘g++‘ terminated with exit code 1“_第1张图片

你可能感兴趣的:(工具问题解决,经验分享)