Windows 8上的C ++在启动后立即关闭程序 [英] C++ on windows 8 closes a program immediately after launching

查看:160
本文介绍了Windows 8上的C ++在启动后立即关闭程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了minGW和eclipse CDT,而控制台仍然在做一些奇怪的事情。程序的代码是

I installed minGW and the eclipse CDT, and the console keeps doing something weird. The code of the program is

using namespace std;
#include <iostream>

int main() {
    cout << "Hello, windows (8, c++)" << endl;
    //system("PAUSE");
    return 0;
}

你们都知道,它的Hello World程序。现在当我运行这个Eclipse控制台显示一些关于构建的东西,然后变为空白。当我浏览到浏览器中的HelloWorldProgram.exe并运行它时,窗口会闪烁并显示hello world,但是会立即关闭。当我在Mac OSX上执行此操作时,没有问题,窗口保持不变,直到我决定关闭它。现在我知道有一个命令

You all know it, its the Hello World program. Now when I run this the Eclipse console displays some stuff about building, and then goes blank. And when I navigate to the HelloWorldProgram.exe in the explorer and run it, a windows flashes up and displays "hello world", but then immediately closes. When I do this on Mac OSX there's no problem, and the windows stays up until I decide to close it. Now I know there's a command

system("PAUSE") //I dont know what I need to import to use this. Could you tell me that too?

哪些会给我或多或少的相同的效果,但我想知道Windows为什么它与OSX不同,我可以做些什么来解决它(bc这使我厌烦了)。
期待您的回复!

Which will give me more or less the same effect, but I'd like to know why Windows does it differently from OSX, and what I can do to fix it (bc this annoys the crap out of me). Looking forward to your replies!

推荐答案

这在Windows上发生,因为这只是Windows控制台的行为。您必须手动打开控制台,然后通过您打开的控制台运行程序,如果您不希望在程序执行后自动关闭窗口。

This happens on Windows because this is just the behavior of the Windows console. You'll have to open up the console manually and then running your program through the console you've opened if you don't want the window to close automatically once the program has executed.

您可能需要查看以下内容:

You may want to take a look at these:

打击控制台关闭问题的最佳做法是什么?

https://superuser.com/questions/186562/how-cani-i-保持终端打开

这篇关于Windows 8上的C ++在启动后立即关闭程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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