无论如何,一旦程序完成并在1次按键后关闭,控制台窗口将保持打开状态吗? [英] Is there anyway to get the console window to stay open once program is done and close after 1 keystroke?

查看:59
本文介绍了无论如何,一旦程序完成并在1次按键后关闭,控制台窗口将保持打开状态吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

命令行程序始终在执行完后关闭窗口。我知道您可以使用 cin.get(); 等待用户输入输入。用户是否可以按任意键(而不是先输入内容然后按Enter键)来关闭程序?我不想使用 system( PAUSE),因为它特定于Windows,并且运行缓慢。

A command line program always closes the window after it has finished executing. I know you can use cin.get(); to wait for the user to enter input. Is there a way where the user could press any key (instead of entering something then pressing enter) to close the program? I don't want to use system("PAUSE") as it's Windows specific and slow.

我想要它会暂停,以便用户可以看到它已成功完成以及其他详细信息。它可能不会从已经打开的命令行中运行,而可执行文件将被双击运行。

I want it to pause so that the user can see it completed successfully and other details. It would probably not be run from an already open command line and the executable would be double clicked to run.

推荐答案

是。 system( PAUSE)是一种方法。简单的 getchar()或 cin应该绝对等效:)

Yes. "system("PAUSE") is one way. A simple "getchar()" or "cin" should be absolutely equivalent :)

这篇关于无论如何,一旦程序完成并在1次按键后关闭,控制台窗口将保持打开状态吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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