如何让窗口在 C++ 之后保持打开状态代码运行?
可能的重复:
如何阻止 C++ 控制台应用程序立即退出?
我正在尝试查看我的结果,我该如何处理我的代码,以便查看我所做的是否正确?
#include <iostream>
using namespace std;
int main()
{
cout << "C++" << endl;
cout << "The sum of 11 + 12 = " << 30/2 << endl;
return 0;
}
Possible Duplicate:
How to stop C++ console application from exiting immediately?
I am trying to see my results, what do I do to my code so I can see if what I did is correct?
#include <iostream>
using namespace std;
int main()
{
cout << "C++" << endl;
cout << "The sum of 11 + 12 = " << 30/2 << endl;
return 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为你的意思是程序结束后你的DOS终端就会关闭。
常见的解决方案是在程序末尾、
返回 0 之前调用
。这迫使程序在退出之前等待一些用户输入。cin
、scanf
或getch
更好的方法是编译程序,然后自己在 DOS 提示符下运行它。只需启动 DOS 提示符,
cd
到程序所在的目录并从那里运行它。I think what you mean is that your DOS terminal closes as soon as your program ends.
A common solution is to have a call to
cin
,scanf
orgetch
at the end of your program, just before yourreturn 0
. This forces the program to wait for some user input before exiting.A better way is to compile your program and then run it from within a DOS prompt yourself. Just start up a DOS prompt,
cd
to the directory your program is in and run it from there.在代码末尾使用 getchar() 或仅从控制台运行可执行文件。
Use
getchar()
at the end of code or just run your executable file from console.Windows 上的另一种方式:system("pause");
An other way on windows: system("pause");