【发布时间】:2014-10-04 08:28:00
【问题描述】:
我的以下基本 C++ 代码不起作用。当我在 Visual Studio express 中运行它时,它只是在我输入第二个数字后关闭命令提示符。提前致谢。
#include <iostream>
using namespace std;
int main()
{
int num1, num2, answer;
cout << " Enter a number: ";
cin >> num1;
answer = num1 * num1;
cout << " the sum of the number is: " << answer << endl;
cout << "Enter a 2nd number";
cin >> num2;
answer = answer + num2;
cout << "The sum of the two numbers is: " << answer << endl;
cin.get();
return 0;
}
【问题讨论】:
-
尝试在第一个输入之后也放一个 cin.get()。
标签: c++ visual-c++ visual-studio-2012