编译错误:无法打开预编译的 header.pch -- 没有这样的文件或目录

新手上路,请多包涵

我最近购买了 Bjarne Stroustrup 的“编程:使用 C++ 的原则和实践”一书,并一直在关注它。我目前被困在一个早期项目中,我需要输出一些文本字符串。在 Windows 10 Lenovo Yoga 2 Pro 笔记本电脑上使用 Visual Studio Community 2015 更新 1,我尝试编译该项目,但遇到了详细的错误:

“无法打开预编译的头文件:Debug\Finding the Upstairs Bathroom.pch’:没有这样的文件或目录”。该项目的名称恰如其分地命名为“寻找楼上浴室.cpp”。这是代码:

 // I have the headers "stdafx.h" as well as this specific header lib
// Bjarne Stroustrup created and which I had linked
// called "../../std_lib_facilities.h", which contains the standard C++ lib functions.

(#) define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS 1

int main()`// Main function`

{
    cout << "Take the key out of your right pants pocket\n"; // Outputs string of text

    cout << "Unlock the front door of the house\n";

    cout << "Open the front door and step inside\n";

    cout << "Lock the front door using the key\n";

    cout << "Move up the stairs, taking them two at a time\n";

    cout << "Walk to the second door on the left and face it directly\n";

    cout << "Using the door handle, turn it and push the door forward\n";

    cout << "Enter the bathroom while leaving the door open behind you\n";

    keep_window_open();

    return 0;
}

如果有人能够弄清楚如何解决我的错误,我将不胜感激。

原文由 Rudis 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 564
1 个回答

有 2 个选项可以解决此问题:

  • 重建整个项目。这应该(重新)创建预编译的头文件(或首先选择 Build/Clean Solution )。

  • 关闭预编译头文件。 Project settings / C/C++ / Precompiled headers / Not Using Precompiled Headers

原文由 Danny_ds 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题