如何让程序暂停? [英] How do I get a program to pause?

查看:118
本文介绍了如何让程序暂停?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在.txt上创建了这个程序,我转换为.bat。每当我尝试运行程序时,它会立即打开和关闭。这是;



I made this program on a .txt I converted to .bat. Whenever I try to run the program it opens and closes instantly. Here it is;

#include <iostream>
int main()
using namespace std;{


int main ()
{
	
	int i;
	cout <<"Input orbital period in seconds: ";
	cin >> t;
	cout << "Orbital time= " << t;
	cout << "Input Object distance from sun in meters: ";
	(cin >> d;
	cout << "Orbital distance= " << d;
	
	g = (6.6 * 10^-11)

	m = (d^3 * (4 * 3.14159)^2) / (g * (t^2))

	cout << "Object mass= " << m;


}

推荐答案

尝试输入 getchar(),因此用户必须按键才能继续...请参阅参考 [ ^ ]
Try putting a getchar() in there so the user has to hit a key to continue ... see reference[^]


Quote:

cout<< 对象质量=<< m;

cout << "Object mass= " << m;





Put



Put

cout << "Press enter to continue...\n" ;
string dummy; // Have not used C++ in a while use any data type that you enjoy.
// This variable does nothing. You need your console to wait for an input.
// Which acts like a 'Pause'
cint >> dummy;


除了其他人所说的,如果你在Windows操作系统中使用它(例如Visual Studio作为IDE),我建议你使用它这个仅限Windows的命令。



Apart from what others have said, if you are using this in Windows OS (Visual Studio for example as an IDE) I would recommend that you use this Windows-only command.

system("pause");





其他答案也有效,但这是一个单一的功能暂停应用程序。此外,这也将做Clark的代码所做的事情,它会自动显示消息继续。



唯一的缺点是它不是跨平台功能。它仅限Windows。


这篇关于如何让程序暂停?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆