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

时间:2016-01-14 20:53:32

标签: c++ compiler-errors visual-studio-2015

我最近购买了Bjarne Stroustrup的文字“Programming:Principles and Practice Using C ++”,并一直在关注它。我目前停留在早期项目中,我需要输出一些文本字符串。使用Visual Studio Community 2015更新1,在Windows 10 Lenovo Yoga 2 Pro笔记本电脑上,我尝试编译该项目,但遇到了错误详细信息:

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

// 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;
}

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

2 个答案:

答案 0 :(得分:5)

有两种方法可以解决这个问题:

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

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

答案 1 :(得分:0)

从Danny_ds提供的选项中选择Appart,您可以:

  • 创建预编译的标头:Project settings / C/C++ / Precompiled Headers

    Precompiled Headers: Create (/Yc)

    Create VS precompiled headers

  • 禁用预编译头。 Project settings / C/C++ / Precompiled Headers

    Precompiled Headers: Not Using Precompiled Headers

我第一次不得不创建预编译头文件时遇到了问题。