A brief analysis of where the precompiled header file in VC is placed

  • 2020-04-01 23:39:12
  • OfStack

To write in C++, you must use the precompiled header file, that's it Stdafx. H.
But I always thought that if you included stdafx.h in your.cpp file, you were using a precompiled header file.
In VC++, the precompiled header file refers to the header file in stdafx.h will have an effect.
As follows:
File: stdafx. H

// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#ifndef _WIN32_WINNT        // Allow use of features specific to Windows XP or later.                   
#define _WIN32_WINNT 0x0501    // Change this to the appropriate value to target other versions of Windows.
#endif                        
#define WIN32_LEAN_AND_MEAN        // Exclude rarely-used stuff from Windows headers


//Note that this is where the header file that you want to use the precompiled effect is located.
#include <Windows.h>
#include "xxx.h"


// TODO: reference additional headers your program requires here

In stdafx.cpp, the default is as follows:

// stdafx.cpp : source file that includes just the standard includes
// CPPTestHelper.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file


Related articles: