如何解决在 Visual Studio-2013 for C++ 中输入或编译后输出控制台消失的问题?

How can I overcome the issue of output console disappearing after taking input or compiling in Visual Studio-2013 for C++?

我是 C++ 编码新手,在 Visual studio 环境中。我正在编译查找一个数字的 sqrt 的简单代码,甚至 运行 但是在将数字作为输入后控制台消失了,我留下了调试消息和程序的最终消息以退出代码 0 终止。基本上没有显示输出。

#include <cmath>
#include <iostream>

int main()
{
    double x{ 0.0 };

    std::cout << "Enter x-";
    std::cin >> x;

    if (x >= 0)
        std::cout << "\nSqrt(" << x << ") = " << std::sqrt(x) << std::endl;
    else
        std::cout << "\nWrong Value - cannot compute sqrt\n";
}

代码看起来不错,运行在线编译器上。我已经尝试从 Linker->System->Sub-system->Console (/SUBSYSTEM:CONSOLE) 检查 'console' 选项。但是没有任何效果。

似乎还生成了某些调试消息,其中一些我在下面显示 -

......
'Project2.exe' (Win32): Loaded 'C:\Program Files (x86)\Citrix\System32\CtxGraphicsHelper.dll'. Cannot find or open the PDB file.
'Project2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\setupapi.dll'. Symbols loaded.
'Project2.exe' (Win32): Loaded 'C:\Program Files (x86)\Citrix\System32\mmhook.dll'. Cannot find or open the PDB file.
'Project2.exe' (Win32): Loaded 'C:\Program Files (x86)\Citrix\System32\Sfrhook.dll'. Cannot find or open the PDB file.
'Project2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\wtsapi32.dll'. Symbols loaded.
The thread 0x498 has exited with code 0 (0x0).
The thread 0x2500 has exited with code 0 (0x0).
The thread 0x30f0 has exited with code 0 (0x0).
'Project2.exe' (Win32): Loaded 'C:\Program Files (x86)\Citrix\System32\ShellHook.dll'. Cannot find or open the PDB file.
'Project2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shell32.dll'. Symbols loaded.
'Project2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\windows.storage.dll'. Symbols loaded.
'Project2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shlwapi.dll'. Symbols loaded.
'Project2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\SHCore.dll'. Symbols loaded.
'Project2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\profapi.dll'. Symbols loaded.
'Project2.exe' (Win32): Loaded 'C:\Program Files (x86)\Citrix\System32\scardhook.dll'. Cannot find or open the PDB file.
'Project2.exe' (Win32): Loaded 'C:\Program Files (x86)\Citrix\System32\twnhook.dll'. Cannot find or open the PDB file.
'Project2.exe' (Win32): Loaded 'C:\Program Files (x86)\Citrix\System32\cxinjime.dll'. Cannot find or open the PDB file.
The program '[10912] Project2.exe' has exited with code 0 (0x0).

我尝试检查工具->调试->符号->Microsoft 符号服务器。找到了一些 PDF 文件,有些则没有。我想找到这个问题的根源,基本上让我的程序按照其编码的方式运行,输出控制台接受输入并显示结果。

可以在代码末尾临时加一行:

system("pause");

别忘了包括:#include <cstdlib>