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

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

问题描述

我安装了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.

您可能想看看这些:

What is the Best Practice for Combating the Console Closing Issue?

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

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

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