vs2008控制台程序一闪而过解决方法

摘自微软的技术支持论坛
http://social.msdn.microsoft.com/Forums/en/Vsexpressvc/thread/1555ce45-8313-4669-a31e-b95b5d28c787

Alot of users have been asking why their console application terminatesimmediately after running/debugging their program in the Visual C++ IDE. Users claim to see a quick flash of the console applicationand then it disappears.

Thisis due to the fact that when your program is run, it creates a temporaryconsole session to invoke your application.  Without any code toexplicitly keep the console open (i.e. requiring that the user enter in a valueusing cin >>), the console terminates immediately after the codecompletes.  This is why you see a quick flash of your console application.

Thereare a few things you can do to see the output of your program.

    1.  Start your application without debugging (Ctrl+F5).  When doing this, the C++ IDE creates a batch file that executes your code and displays the text "Press any key to continue".  This will allow the console to stay on the screen and allow you to view the output.
    2. Set a breakpoint in the code and run with debugging (F5).  When you hit the breakpoint, you can see the console window's current output.
    3. Run the application from a command prompt.  Press Start->All Programs->Visual C++ 2005 Express Edition->Visual Studio Tools->Visual Studio 2005 command prompt.  Then navigate to the directory (using 'cd') where the .exe is located.  Run the application by typing in the name of the .exe at the command prompt.  You will see the output from the program in the command prompt.

Hopefullythis will help people get their first C++ application up and running!
简单的说就是
1 用ctrl + F5 代替 F5  
2 在debug模式设置断点 
3 手动打开cmd控制台,运行程序

4  在程序结尾加上 system("pause"); 
第一种和四种比较直接方便

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值