VSCode C++终端进程已终止,退出代码为:1

VSCode C++ Terminal Process terminated with exit code: 1

本文关键字:代码 退出 终止 C++ 终端 进程 VSCode      更新时间:2023-10-16

我想用VSCode在C++中做基本的数据排序,需要包含一个新的库;在这样做的时候,我想我不小心在后台搞砸了一些严重的事情(可能是.json文件之一),因为每次我试图通过MinGW用g++构建最基本的程序时,我都会收到消息"终端进程终止,退出代码:1。即使是我知道有效的、以前制作成.exe的基本"Hello World"项目,也不会再编译成可执行文件。helloworld.cpp

#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
std::cout <<"Hello World!n";

}

我尝试重新启动窗口,重新安装VSCode,在不同的目录中启动一个新项目,使用默认的json文件,以防我更改了不该更改的内容。。。我习惯于通过gfortran用FORTRAN和通过Anaconda用Spyder用Python做类似的数据任务,但我对C++和VSCode都缺乏经验,并且对做像运行程序这样简单的事情的复杂性越来越感到沮丧。

任何关于如何解决这一问题的建议都将是有益的;我检查了其他类似的问题,没有任何建议奏效。

Tasks.json

{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: g++.exe build active file",
"command": "D:\MinGW\bin\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}

c_cpp_properties.json

{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.17134.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.14.26428/bin/Hostx64/x64/cl.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "msvc-x64"
}
],
"version": 4
}

启动.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": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/helloworld.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false
}
]

}

对我来说,问题是在运行时出现了一个编译器以前没有注意到的错误。因此,即使调试器没有发现错误,也必须检查脚本是否正常。

我也遇到了同样的问题,以防退出代码以-1结束,因为花了2个小时,然后发现代码中有错误,因为当我点击错误按钮时,没有错误,因为我在看到了很多程序后没有得到预期的输出,我发现程序中的小错误增加了复杂性,所以我建议仔细检查代码文件的每一行,在我的例子中,问题是通过在代码中进行更正来解决的。