Home c++ fatal error C1010: You may have forgotten to add the "#include" pch.h...

fatal error C1010: You may have forgotten to add the “#include” pch.h “” directive to the source




When compiling this code:

# include "pch.h"
#include & lt; iostream & gt;
using namespace std;
class b;
class a {
  friend int sum (a, b);
  int i;
  a () {
    cout & lt; & lt; "Enter i:";
    cin & gt; & gt; i;
class b {
  friend int sum (a, b);
  int y;
  b () {
    cout & lt; & lt; "Enter y:";
    cin & gt; & gt; y;
int sum (a first, b second) {
  return (first.i + second.y);
int main () {
  a first;
  b second;
  cout & lt; & lt; sum (first, second) & lt; & lt; endl;
  cin.get ();
  return 0;

throws an error

fatal error C1010: Unexpected end of file while searching for precompiled header. You may have forgotten to add the “#include” pch.h “” directive to the source.

Why this is so – is not clear. All libraries are connected. (Worked in VS)

Answer 1, authority 100%

If you are not using precompiled headers in your project, set the New / Use precompiled source headers property to Do not use precompiled headers. To set this compiler option, follow these steps:

  • In the Solution Explorer pane of the project, right-click
    project name and select Properties.

  • In the left pane, click the C / C++ folder.

  • Click the Precompiled Headers node.

  • In the right pane, click Create / Use Preview
    compiled header “and then click” Don’t use
    precompiled headers “.

Make sure you haven’t accidentally deleted, renamed or deleted the header file (stdafx.h by default) from the current project. This file must also be included before any other code in your source files using #include “stdafx.h”. (This header file is listed as a “Create / use PCH via file” project property)

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions