【问题标题】:My cmd output just closes almost instantly and I cant seem to figure out why [duplicate]我的 cmd 输出几乎立即关闭,我似乎无法弄清楚为什么[重复]
【发布时间】:2017-10-24 04:45:04
【问题描述】:

这是我的代码,非常简单,仅用于测试。

 #include <iostream>

 using namespace std;
 int main()
 {
 int a, b, c;
 a = 2;
 b = 7;
 c = a + b * 3;
 cout << c;
 return 0;
 }

我得到了这个调试 “test.exe”(Win32):加载“C:\Users\Jacob\Documents\Visual Studio 2017\Projects\test\Debug\test.exe”。已加载符号。 “test.exe”(Win32):已加载“C:\Windows\syswow64\ntdll.dll”。无法找到或打开 PDB 文件。 “test.exe”(Win32):已加载“C:\Windows\syswow64\kernel32.dll”。无法找到或打开 PDB 文件。 'test.exe' (Win32): 卸载'C:\Windows\syswow64\kernel32.dll' “test.exe”(Win32):已加载“C:\Windows\syswow64\kernel32.dll”。无法找到或打开 PDB 文件。 “test.exe”(Win32):加载“C:\Windows\syswow64\KernelBase.dll”。无法找到或打开 PDB 文件。 “test.exe”(Win32):已加载“C:\Windows\syswow64\msvcp140d.dll”。无法找到或打开 PDB 文件。 “test.exe”(Win32):已加载“C:\Windows\syswow64\vcruntime140d.dll”。无法找到或打开 PDB 文件。 “test.exe”(Win32):已加载“C:\Windows\syswow64\vcruntime140d.dll”。无法找到或打开 PDB 文件。 'test.exe' (Win32): 卸载'C:\Windows\syswow64\vcruntime140d.dll' “test.exe”(Win32):加载“C:\Windows\syswow64\ucrtbased.dll”。无法找到或打开 PDB 文件。 “test.exe”(Win32):加载“C:\Windows\syswow64\ucrtbased.dll”。无法找到或打开 PDB 文件。 'test.exe' (Win32): 卸载'C:\Windows\syswow64\ucrtbased.dll' “test.exe”(Win32):加载“C:\Windows\syswow64\ucrtbased.dll”。无法找到或打开 PDB 文件。 'test.exe' (Win32): 卸载'C:\Windows\syswow64\ucrtbased.dll' “test.exe”(Win32):已加载“C:\Windows\syswow64\kernel.appcore.dll”。无法找到或打开 PDB 文件。 “test.exe”(Win32):已加载“C:\Windows\syswow64\msvcrt.dll”。无法找到或打开 PDB 文件。 “test.exe”(Win32):已加载“C:\Windows\syswow64\rpcrt4.dll”。无法找到或打开 PDB 文件。 “test.exe”(Win32):加载“C:\Windows\syswow64\sspicli.dll”。无法找到或打开 PDB 文件。 “test.exe”(Win32):加载“C:\Windows\syswow64\cryptbase.dll”。无法找到或打开 PDB 文件。 “test.exe”(Win32):加载“C:\Windows\syswow64\bcryptprimitives.dll”。无法找到或打开 PDB 文件。 “test.exe”(Win32):加载“C:\Windows\syswow64\sechost.dll”。无法找到或打开 PDB 文件。 线程 0x128 以代码 0 (0x0) 退出。 线程 0x1f08 以代码 0 (0x0) 退出。 线程 0x15d0 以代码 0 (0x0) 退出。 程序“[1976] test.exe”已退出,代码为 0 (0x0)。

【问题讨论】:

  • return 0这一行放一个断点。
  • 这只是意味着您没有安装上述库的调试版本;别担心,最后一行The program '[1976] test.exe' has exited with code 0 (0x0). 显示一切都已正确完成。哦,在return 0; 之前添加getchar();,这样窗口就不会立即关闭。

标签: c++ windows


【解决方案1】:

您使用main() 函数创建的经典C/C++ 风格程序在Windows 中称为控制台程序。这意味着它应该在控制台窗口中运行;标准输入和输出将出现在该控制台窗口中。

如果您没有控制台窗口,Windows 会在程序启动时为您创建一个。但是当程序结束时它会立即销毁它。

有很多技术可以解决这个问题。首先是从您已经打开的控制台启动程序 - 如果它没有自动打开它,Windows 不会关闭它。但是,如果您尝试使用调试器,那将不起作用。其次是让程序在退出之前在最后暂停。您可以通过阅读 cin 中的内容来做到这一点,或者按照我在 cmets 中的建议,只需在程序末尾放置一个断点即可。

您在 Visual Studio 输出窗口中看到的消息不是程序的输出,它们是由 Windows 本身或 C++ 运行时生成的调试消息。你看到的关于丢失 PDB 文件的那些是完全无害的,它们意味着你没有 Windows 提供的 DLL 的调试信息,这是完全正常的。

【讨论】:

    猜你喜欢
    • 2014-05-19
    • 2021-06-04
    • 2021-04-26
    • 1970-01-01
    • 1970-01-01
    • 2011-07-08
    • 2020-11-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多