'How do I fix unexpected end of file error with pch.h
So I have been trying to learn cpp and I was writing a program, and when I try to build the solution, it gives an error saying
unexpected end of file while looking for precompiled header. Did you forget to add #include "pch.h" to your source?
Then I included it and I got the same error, and also another saying
cannot open source file pch.h
Solution 1:[1]
One option, if you are new to c++, is to just turn off pre-compiled headers in the project settings.

Solution 2:[2]
Your .cpp file is probably not in the same directory as pch.h
Solution 3:[3]
Try adding the directory that your pch.h is in to the additional includes, even if it is at the root of your project.

Solution 4:[4]
quick solution to a frustrating issue when trying to add .pch to an exisiting project: if you have a /include /src dir structure, it might not work, unless you place the "pch.h" and "pch.cpp" in the same dir /src.
Also: mark the "MyPreComp.cpp" as /Yc - create, and in the .cpp files you want to use the .pch set them to Yu - use.
#include "pch.h" as the first #include in the .cpp
NB. You need to set "not using precompiled headers" to all .cpp files not using them, yes, it IS a hassle.
( Visual Studio 2019 )
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | selbie |
| Solution 2 | SaweyHD |
| Solution 3 | ZackOfAllTrades |
| Solution 4 |

