c++ - Visual C++ 输出退出得如此之快

标签 c++ visual-studio-2010 visual-studio visual-c++ visual-c++-2010

<分区>

Possible Duplicate:
Visual Studio terminates my console application too fast

我是 100% 的 Visual Studio C++ 新手。我也是 C++ 的新手,到目前为止我使用 netbeans 和 cygwin。今天我安装了 Visual C++ 2012 并运行了以下简单代码

// HelloWorld.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

using namespace std;


int main()
{
    cout << "Hello World" << endl;
}

控制台窗口出现了,而且速度太快了,我也没有机会看到输出,提到以下内容。

'HelloWorld.exe': Loaded 'C:\Users\yohan\Documents\Visual Studio 2010\Projects\HelloWorld\Debug\HelloWorld.exe', Symbols loaded.
'HelloWorld.exe': Loaded 'C:\Windows\System32\ntdll.dll', Cannot find or open the PDB file
'HelloWorld.exe': Loaded 'C:\Windows\System32\kernel32.dll', Cannot find or open the PDB file
'HelloWorld.exe': Loaded 'C:\Windows\System32\KernelBase.dll', Cannot find or open the PDB file
'HelloWorld.exe': Loaded 'C:\Windows\System32\msvcp100d.dll', Symbols loaded.
'HelloWorld.exe': Loaded 'C:\Windows\System32\msvcr100d.dll', Symbols loaded.
The program '[3436] HelloWorld.exe: Native' has exited with code 0 (0x0).

我浏览了互联网,有人建议将项目属性 > 配置属性 > 链接器 > 调试选项卡 > 生成调试信息设置为"is"。这已经设置为是,但仍然不好。我也计划在这个 IDE 中使用 opencv。所以请帮忙!!!

最佳答案

编辑:你显然不应该将 cin 放入真正的程序中,除非你真的想读入输入。

发生的事情是您的程序按照您的指示打印“Hello World”,然后完成。

VS 作为一个 MS 程序,只会为你的程序创建一个终端,直到它完成,然后它会关闭终端。

为了查看输出,您可以将其放在 cout 之后:

string buffer;
cin >> buffer;

这将等待您在终止程序之前按回车键。

关于c++ - Visual C++ 输出退出得如此之快,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12226148/

相关文章:

c# - "legacy".NET 项目是否也可以使用新的 NuGet 3 功能?

c# - 如何向 Visual Studio 2017 添加功能?

c++ - 如何使用enable_if定义不同的成员函数?

c++ - 编写递归 C++ 函数,计算并返回数组中整数的乘积

c++ - 将简单的 exe 运行到运行 microsoft/windowsservercore 的 docker 容器中

c# - 无法使用C#连接到其他机器的mysql服务器?

visual-studio-2010 - 在Visual Studio 2010中调试经典ASP

c++ - Visual Studio 2013 调试器显示 std::string 的奇怪值

c# - VB 如何检查文本框中的负值?

c# - 为什么 Visual Studio 2019 会删除对新 .razor 文件的监视?