如何让屏幕暂停?

发布于 2024-08-30 16:51:12 字数 1239 浏览 6 评论 0原文

可能的重复:
如何阻止 C++ 控制台应用程序立即退出?

所以我正在学习 C++,我得到了这个例子,我想运行它。但我无法让它保持正常状态,除非我改变它。在我释放程序后,如何让 Microsoft Visual 2010 在程序结束时保持屏幕显示?

#include<iostream>
using namespace std;

int area(int length, int width);        /* function declaration */

/* MAIN PROGRAM: */
int main()
{
    int this_length, this_width;      

    cout << "Enter the length: ";             /* <--- line 9 */
    cin >> this_length;
    cout << "Enter the width: ";
    cin >> this_width;
    cout << "\n";                             /* <--- line 13 */

    cout << "The area of a " << this_length << "x" << this_width;
    cout << " rectangle is " << area(this_length, this_width);

    return 0;
}
/* END OF MAIN PROGRAM */

/* FUNCTION TO CALCULATE AREA: */
int area(int length, int width)   /* start of function definition */
{
    int number;

    number = length * width;

    return number;
}                                 /* end of function definition */
/* END OF FUNCTION */

Possible Duplicate:
How to stop C++ console application from exiting immediately?

So im learning c++ and i was given this example and i wanted to run it. But i cannot get it to stay up, unless i change it. How do i get Microsoft visual 2010 to keep up the screen when it gets to the end of the program after I release it?

#include<iostream>
using namespace std;

int area(int length, int width);        /* function declaration */

/* MAIN PROGRAM: */
int main()
{
    int this_length, this_width;      

    cout << "Enter the length: ";             /* <--- line 9 */
    cin >> this_length;
    cout << "Enter the width: ";
    cin >> this_width;
    cout << "\n";                             /* <--- line 13 */

    cout << "The area of a " << this_length << "x" << this_width;
    cout << " rectangle is " << area(this_length, this_width);

    return 0;
}
/* END OF MAIN PROGRAM */

/* FUNCTION TO CALCULATE AREA: */
int area(int length, int width)   /* start of function definition */
{
    int number;

    number = length * width;

    return number;
}                                 /* end of function definition */
/* END OF FUNCTION */

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

幻梦 2024-09-06 16:51:12

在 Visual C++ 中,您可以:

  • main 的右大括号处放置一个断点,然后附加到调试器运行(调试 -> 开始调试)。当断点被击中时,您将能够查看控制台窗口。
  • 与调试器分离运行(调试 -> 启动而不调试)。当应用程序终止时,控制台窗口将保持打开状态,并显示“按任意键继续...”提示。

In Visual C++ you can either:

  • Put a breakpoint at the closing brace of main and run attached to the debugger (Debug -> Start Debugging). When the breakpoint is hit you will be able to view the console window.
  • Run detached from the debugger (Debug -> Start Without Debugging). When the application terminates, the console window will stay open with a "Press any key to continue..." prompt.
记忆で 2024-09-06 16:51:12

我通常使用 cin.getchar() 来等待一个字符。

I usually use cin.getchar() to wait for a character.

一杆小烟枪 2024-09-06 16:51:12

尝试将 system("PAUSE"); 添加到 main 末尾的 return 语句之前。

这会执行 PAUSE 系统命令,等待按下某个键。

Try adding system("PAUSE"); to the end of main before the return statement.

This executes the PAUSE system command which waits for a key to be pressed.

甲如呢乙后呢 2024-09-06 16:51:12

最简单的方法是等待用户按下某个键,然后再从 main 返回。

The easiest way is to wait for the user to press a key before returning from main.

东风软 2024-09-06 16:51:12

您的代码中已经有了答案。在程序末尾添加另一个 cin ;P 用户必须按 Enter 键才能让程序继续并退出

You already have the answer in your code.. add another cin at the end of your program ;P user would have to press enter for program to continue and exit

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文