【问题标题】:The terminal process "C:\WINDOWS\System32\cmd.exe" terminated with exit code: 1终端进程“C:\WINDOWS\System32\cmd.exe”以退出代码终止:1
【发布时间】:2022-01-10 14:44:25
【问题描述】:

在使用Visual Studio Code 计算Leaders in an array 的总和时,我遇到了一个错误:“终端进程“C:\WINDOWS\System32\cmd.exe”以退出代码终止:1。”

我的 C++ 实现如下:

#include<bits/stdc++.h>
using namespace std;

int leader_func(int arr[], int n)
{
  int sum=0;
  int max=arr[n-1];
  for (int i = n-2; i>=0; i--)
   {
     if (max<arr[i])
      {
         sum+=arr[i];
      }
   }
return sum;
}

int main()
{
int arr[4]={33,7,21,14};
int n=4;
cout<<leader_func(arr, n);
return 0;
}

预期输出为:54(即 33 + 21)。

我收到的实际结果:The terminal process "C:\WINDOWS\System32\cmd.exe" terminated with exit code: 1.

可能的原因是什么?以及如何解决这个问题?

【问题讨论】:

  • 无法复制。也许使用#include &lt;iostream&gt; 而不是可怕的#include&lt;bits/stdc++.h&gt;?见:Why should I not #include <bits/stdc++.h>?
  • ... 您可能会在您的 max 变量和在您隐含包含在令人震惊的第一个标题中的其中一个中定义的东西(例如 std::max?)之间遇到某种“冲突”行。

标签: c++ visual-studio error-handling exit-code


【解决方案1】:

改变 项目文件->设置->构建后设置->将\(在末尾)添加到xcopy消息

【讨论】:

    猜你喜欢
    • 2023-01-01
    • 2020-09-28
    • 1970-01-01
    • 2022-07-18
    • 2022-08-11
    • 1970-01-01
    • 1970-01-01
    • 2018-07-25
    • 2015-04-11
    相关资源
    最近更新 更多