问题描述
我是C ++的初学者,我试图写一个程序,找到两个数字的平均值,但当我运行程序,窗口消失,而不允许我看到的结果。有人可以帮助我吗?
感谢
I am a beginner in C++ and I was trying to write a program that finds the average of two numbers, but when I run the program, the window disappears without allowing me to see the result. Can someone please help me?Thanks
#include <iostream>
using namespace std;
int main()
{
int number1,number2,answer;
cout << "number1? ";
cin >> number1;
cout << "number2? ";
cin >> number2;
answer = (number1 + number2)/2;
cout << answer<<endl;
return 0;
}
推荐答案
:
从shell运行程序( cmd.exe
, bash
)
解决方案#1(正确):
从正统文件管理器运行程序。
Solution #1 (proper):
Run program from orthodox file manager. Far Manager or midnight commander.
解决方案#2(替代);
将输出重定向到文件。 program.exe> file.txt
。
Solution #2 (alternative);
Redirect output to file. program.exe >file.txt
from command line.
解决方案3
启动消息框,使用sleep/Sleep延迟程序终止。
Solution #3 (improper):
Launch message box, use "sleep"/"Sleep" to delay program termination.
解决方案#
解决方案5(不正确):
在return 0上设置断点,调试程序。
Solution #5 (improper):
Set breakpoint on "return 0", debug the program.
解决方案#6(windows + msvc):
使用调试版本通过Ctrl + F5从msvc启动程序。您将获得按键以继续提示。
Solution #6 (windows+msvc):
Launch program from msvc by Ctrl+F5 using debug build. You'll get "press key to continue" prompt.
这篇关于C ++初学者,执行窗口快速消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!