precompiled headers in Visual Studio 2018

  • Thread starter Thread starter Zolfaghar
  • Start date Start date
Z

Zolfaghar

Guest
Greetings

I just created my first C++ project in Visual Studio, the following is in there by default:

#include "pch.h"
#include <iostream>

int main()
{
std::cout << "Hello World!\n";
}
I was curious about the pch.h statement and browsed around the solution explorer tray on the right hand side. Noticed pch.cpp, which includes pch.h, and when I looked in there is says to put the header files, which I want to add to precompiled code in there. I also did some reading online about precompiled process / feature or strategy, and found the article here which says to put the header files in stdafx.cpp, which can contain just one #include "stdafx.h" and all the header files that I intend to precompile should go in there. But this is contrary to what is in the comments section of the pch.h file which says: "add headers that you want to pre-compile here". I am confused. Is this simply the case of using a different file name, or is a slightly more complex relationship between the stdafx and pch files? It is not my intention to find discrepancies; I am simply trying to understand the details. I was initially following the tutorial here and they added a #include "stdafx.h", but I was not able to do that and they were missing the #include "pch.h" file, so I figured maybe the two are interchangeable, but the article mentioned above says that compiling my code with the #include "stdafx.h", results in creating a .pch file. I believe the name of the file does not matter; previously it was stdafx. Visual Studio calls it pch, which brings me to my last question; how is all related, or not to the ipch folder in the project directory? That has one file in it with the ipch extension.

Continue reading...
 
Back
Top