简体   繁体   English

程序在Ubuntu 14.04和GCC中无法正确编译

[英]Program Not Compiling Correctly In Ubuntu 14.04 and GCC

I recently dual-booted my Windows PC with Ubuntu 14.04 LTS and I'm using Code::Blocks as my IDE of choice and GCC as my compiler. 我最近使用Ubuntu 14.04 LTS双重引导了Windows PC,并且将Code :: Blocks作为选择的IDE,并将GCC作为编译器。

I'm a Java programmer learning C++ and I wrote a simple addition program that takes two numbers and adds them together. 我是一名学习C ++的Java程序员,我编写了一个简单的加法程序,该程序将两个数字加在一起。 When I run the program I put in the first number then the second number and instead of telling me my answer, it skips that and I just hit enter and end the program. 当我运行程序时,我输入第一个数字,然后输入第二个数字,而不是告诉我我的答案,而是跳过了这个过程,而我只是按下Enter键并结束程序。

Here's my code: 这是我的代码:

#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";

}

It sounds like you're running your program in an environment that closes the terminal window when the program has finished. 听起来您好像在程序完成后关闭终端窗口的环境中运行程序。 If you're using Code::Blocks, you'll want to take these steps. 如果您使用的是Code :: Blocks,则需要执行以下步骤。

Go to Project -> Properties -> Build targets 转到Project -> Properties -> Build targets

Make sure your target is of type Console project and you have checked Pause when execution ends . 确保您的目标是Console project类型,并且Pause when execution ends选中了Pause when execution ends

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM