C ++在Windows上 - 控制台窗口只是闪烁和消失。这是怎么回事? [英] C++ on Windows - the console window just flashes and disappears. What's going on?

查看:106
本文介绍了C ++在Windows上 - 控制台窗口只是闪烁和消失。这是怎么回事?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

Visual Studio控制台应用程序 - 防止窗口关闭。


我开始在Windows上学习C ++,我正在尝试几个不同的开发环境:
1. Netbeans与Cygwin编译器
2. MS Visual Studio 2010



对于任何一个,当我写一个非常简单的Hello World程序,我构建它,它的罚款。但是当我尝试运行该程序时,命令提示窗口弹出非常快,然后立即消失。



无论是在Debug还是Release配置,这都会发生。请帮助这 - 我看不到我的程序输出! :



EDIT1:
感谢回复,这是我的代码:

  #include< iostream> 

int main()
{
std :: cout< <这是一个测试。<< std :: endl;
return 0;
}
pre>

我试过Ctrl + F5的开始而不调试,这不工作,它仍然闪烁黑色控制台屏幕,然后消失马上。



我也试过添加在std :: cin.get();这适用于Ctrl + F5,但不是一个真正的... inelegant的解决方案?



断点工作,但是我必须使用调试运行,控制台窗口闪烁和消失,但是它保持在任何方式让控制台保持在前台,所以我可以立即看到程序输出。看起来像这应该如何工作。



任何更多的想法? c> Ctrl + F5工作?

解决方案

F5 (无调试运行)。这将在关闭窗口之前提示,这是你想要的。


Possible Duplicate:
Visual Studio Console App - Prevent window from closing.

I'm starting to learn C++ on Windows and I'm trying a few different development environments: 1. Netbeans with Cygwin compiler 2. MS Visual Studio 2010

For either of them, when I write a very simple Hello World program, I build it and it's fine. But when I try to run the program, the command prompt window pops up really quick and then disappears right away.

This happens whether it's in Debug or Release config. Please help with this - I can't see my program output! :(

Thanks.

EDIT1: Thanks for the replies. This is my code:

#include <iostream>

int main()
{
    std::cout << "This is a test." << std::endl;
    return 0;
}

I tried Ctrl+F5 for "Start without Debugging" and that doesn't work. It still flashes the black console screen then disappears right away.

I also tried adding in std::cin.get(); and this works with Ctrl+F5, but isn't that a really... inelegant workaround solution? I'd rather have my program in the final form.

The breakpoint works, but then I have to run with debugging and the console window flashes and disappears, but then it stays in the background. Any way to get the console to stay in the foreground so I can see program output right away? Seems like that's how it should work.

Any more ideas? Why wouldn't Ctrl+F5 work?

解决方案

After you are done with your program, press Ctrl + F5 ( Run without debugging). This will prompt before closing the window and this is what you want.

这篇关于C ++在Windows上 - 控制台窗口只是闪烁和消失。这是怎么回事?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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