【问题标题】:Code won't compile代码无法编译
【发布时间】:2014-03-03 15:30:13
【问题描述】:

我正在使用 Microsoft Visual Studio Express 2013 并编写了以下代码

#include <iostream>
using namespace std;
int main()
{
    cout << "Hello world!";
    return 0;
}

我收到以下错误

1 IntelliSense:PCH 警告:找不到合适的标头停止位置。未生成 IntelliSense PCH 文件。

2 IntelliSense:需要声明 错误 3 错误 C1010:查找预编译头时文件意外结束。您是否忘记将 '#include "stdafx.h"' 添加到您的源代码中?

我尝试添加 '#include "stdafx.h" 但这没有区别。我已经勾选了预编译的标头,如果我取消勾选它,我会在尝试构建时收到以下消息。

'ConsoleApplication6.exe' (Win32): Loaded 'C:\Users\Justin\Desktop\ConsoleApplication6\Debug\ConsoleApplication6.exe'. Symbols loaded.
'ConsoleApplication6.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Cannot find or open the PDB file.
'ConsoleApplication6.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file.
'ConsoleApplication6.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Cannot find or open the PDB file.
'ConsoleApplication6.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp120d.dll'. Cannot find or open the PDB file.
'ConsoleApplication6.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcr120d.dll'. Cannot find or open the PDB file.
'ConsoleApplication6.exe' (Win32): Loaded 'C:\Windows\SysWOW64\guard32.dll'. Cannot find or open the PDB file.
'ConsoleApplication6.exe' (Win32): Loaded 'C:\Windows\SysWOW64\user32.dll'. Cannot find or open the PDB file.
'ConsoleApplication6.exe' (Win32): Loaded 'C:\Windows\SysWOW64\gdi32.dll'. Cannot find or open the PDB file.
'ConsoleApplication6.exe' (Win32): Loaded 'C:\Windows\SysWOW64\lpk.dll'. Cannot find or open the PDB file.
'ConsoleApplication6.exe' (Win32): Loaded 'C:\Windows\SysWOW64\usp10.dll'. Cannot find or open the PDB file.
'ConsoleApplication6.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcrt.dll'. Cannot find or open the PDB file.
'ConsoleApplication6.exe' (Win32): Loaded 'C:\Windows\SysWOW64\advapi32.dll'. Cannot find or open the PDB file.
'ConsoleApplication6.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sechost.dll'. Cannot find or open the PDB file.
'ConsoleApplication6.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rpcrt4.dll'. Cannot find or open the PDB file.
'ConsoleApplication6.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sspicli.dll'. Cannot find or open the PDB file.
'ConsoleApplication6.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptbase.dll'. Cannot find or open the PDB file.
'ConsoleApplication6.exe' (Win32): Loaded 'C:\Windows\SysWOW64\version.dll'. Cannot find or open the PDB file.
'ConsoleApplication6.exe' (Win32): Loaded 'C:\Windows\SysWOW64\imm32.dll'. Cannot find or open the PDB file.
'ConsoleApplication6.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msctf.dll'. Cannot find or open the PDB file.
'ConsoleApplication6.exe' (Win32): Loaded 'C:\Windows\SysWOW64\fltLib.dll'. Cannot find or open the PDB file.
The program '[4872] ConsoleApplication6.exe' has exited with code 0 (0x0).

【问题讨论】:

  • 为什么这被标记为 VB.NET?
  • 听起来您要么搞砸了一些设置,要么删除了文件并用自己的文件替换了它们。我建议从一个新项目重新开始,并从他们提供的文件开始。
  • 你好,我已经完全重新安装了 Visual Studio,没有工作。
  • 这些不是编译器错误,这些是智能感知错误。您显示的列表是您在调试器中运行程序时的输出。那有什么问题呢?
  • 后者不是编译时错误;他们的符号加载通知只是通知您没有可供调试器用于这些库的符号。您的代码在后一个示例中正确编译 并且 运行了。它做什么取决于你。并注意您的程序的符号已加载 9the first message in your load output during run).

标签: c++


【解决方案1】:

stdafx.h 的问题最好通过不使用预编译头来解决,测试程序不需要它们。

“当您尝试构建时”,您不会收到其他消息列表。这些是运行时消息 - 您的文件已成功构建并运行(退出代码 0 是成功的)。只是程序立即终止。

你可以在你的程序中添加这样的东西来等待一些输入:

#include <iostream>
using namespace std;
int main()
{
  cout << "Hello world!";
  cin.get();  // this will wait for a single character press
  return 0;
}

您应该遵循一个好的教程(或参加课程)来熟悉 Visual Studio - 您需要能够区分 Intellisense“错误”、编译器错误、链接器错误和运行时输出消息,以执行任何严重的编程工作。

【讨论】:

    猜你喜欢
    • 2016-07-08
    • 2017-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多