程序在Ubuntu 14.04和GCC中不能正确编译

Program Not Compiling Correctly In Ubuntu 14.04 and GCC

本文关键字:不能 编译 GCC Ubuntu 程序      更新时间:2023-10-16

我最近用Ubuntu 14.04 LTS双启动我的Windows PC,我使用Code::Blocks作为我选择的IDE和GCC作为我的编译器。

我是一个学习c++的Java程序员,我写了一个简单的加法程序,取两个数字并将它们相加。当我运行程序时,我输入第一个数字然后第二个数字,而不是告诉我我的答案,它跳过了这个,我只按enter键并结束程序。

下面是我的代码:

#include <iostream>
using namespace std;
int main()
{
  int thisisanumber;
  int thisisanothernumber;
  int outputnumber;
  cout<<"Please enter first number: ";
  cin>>thisisanumber;
  cin.ignore();
  cout<<"Please enter second number: ";
  cin>>thisisanothernumber;
  cin.ignore();
  outputnumber = thisisanumber + thisisanothernumber;
  cout<<"Your answer is: "<< outputnumber <<"n";
}

听起来好像你在一个程序结束时关闭终端窗口的环境中运行程序。如果你正在使用Code::Blocks,你将需要执行这些步骤。

转到Project -> Properties -> Build targets

确保您的目标是Console project类型,并且您已经检查了Pause when execution ends