zl程序教程

您现在的位置是:首页 >  其它

当前栏目

浅谈VC中预编译的头文件放那里的问题分析

问题 分析 编译 浅谈 vc 头文件 那里
2023-06-13 09:14:54 时间
用C++写程序,肯定要用预编译头文件,就是那个stdafx.h.
不过我一直以为只要在.cpp文件中包含stdafx.h就使用了预编译头文件,其实不对。
在VC++中,预编译头文件是指放到stdafx.h中的头文件才会有效果。
如下:
file:stdafx.h
复制代码代码如下:

//stdafx.h:includefileforstandardsystemincludefiles,
//orprojectspecificincludefilesthatareusedfrequently,but
//arechangedinfrequently
//
#pragmaonce
#ifndef_WIN32_WINNT       //AllowuseoffeaturesspecifictoWindowsXPorlater.                  
#define_WIN32_WINNT0x0501   //ChangethistotheappropriatevaluetotargetotherversionsofWindows.
#endif                       
#defineWIN32_LEAN_AND_MEAN       //Excluderarely-usedstufffromWindowsheaders

复制代码代码如下:

//各位注意,要想使用预编译效果的头文件要放这里。
#include<Windows.h>
#include"xxx.h"

复制代码代码如下:
//TODO:referenceadditionalheadersyourprogramrequireshere

在stdafx.cpp中保持不变即可,默认如下:
复制代码代码如下:
//stdafx.cpp:sourcefilethatincludesjustthestandardincludes
//CPPTestHelper.pchwillbethepre-compiledheader
//stdafx.objwillcontainthepre-compiledtypeinformation
#include"stdafx.h"
//TODO:referenceanyadditionalheadersyouneedinSTDAFX.H
//andnotinthisfile