如何让屏幕暂停?
可能的重复:
如何阻止 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在 Visual C++ 中,您可以:
main
的右大括号处放置一个断点,然后附加到调试器运行(调试 -> 开始调试)。当断点被击中时,您将能够查看控制台窗口。In Visual C++ you can either:
main
and run attached to the debugger (Debug -> Start Debugging). When the breakpoint is hit you will be able to view the console window.我通常使用 cin.getchar() 来等待一个字符。
I usually use cin.getchar() to wait for a character.
尝试将
system("PAUSE");
添加到main
末尾的return
语句之前。这会执行 PAUSE 系统命令,等待按下某个键。
Try adding
system("PAUSE");
to the end ofmain
before thereturn
statement.This executes the PAUSE system command which waits for a key to be pressed.
最简单的方法是等待用户按下某个键,然后再从 main 返回。
The easiest way is to wait for the user to press a key before returning from main.
您的代码中已经有了答案。在程序末尾添加另一个 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