什么是在Visual Studio 2012中的新C ++项目中自动创建的stdafx.cpp文件 [英] What is stdafx.cpp file that is created automatically in a new c++ project in visual studio 2012

查看:167
本文介绍了什么是在Visual Studio 2012中的新C ++项目中自动创建的stdafx.cpp文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我了解,stdafx.h是一个预编译的头文件,用于在Visual Studio中加快编译时间.当我在Visual Studio 2012中创建一个c ++项目时,还有一个stdafx.cpp.有人可以解释stdafx.h和stdafx.cpp之间的关系吗?

From what i understand stdafx.h is a precompiled header file and is used to make compile time faster in visual studio. When i create a c++ project in visual studio 2012 there is also a stdafx.cpp. Can someone explain the relationship between stdafx.h and stdafx.cpp?

推荐答案

预编译头可以大大加快项目中.cpp文件的编译速度.按照约定,它是stdafx.h,其中包含要预编译的所有.h文件.您可以随意命名,但项目模板只会选择stdafx.h

Pre-compiled headers can greatly speed the up the compilation of the .cpp files in your project. By convention, it is stdafx.h that #includes all of the .h files that you want to be precompiled. You can name it anything you want but the project template just picks stdafx.h

但是在此之前,必须有一个 .cpp文件,该文件包含#stdafx.h并首先进行编译.在项目中所有其他.cpp文件之前.完成后,编译器可以使用创建的.pch文件并快速编译所有其他.cpp文件,而不再需要实际上#include头文件了.

But before that can work, there must be one .cpp file that #includes stdafx.h and gets compiled first. Before all the other .cpp files in your project. Once that's done, the compiler can use the .pch file that was created and quickly compile all the other .cpp files, no longer having to actually #include the headers anymore.

Stdafx.cpp是一个.cpp文件.它具有与所有其他.cpp文件不同的设置,并通过来构建/Yc . 创建预编译的头文件"选项.

Stdafx.cpp is that one .cpp file. It has a setting that's different from all the other .cpp files, it gets built with /Yc. The "Create precompiled header file" option.

更新:28年后,微软在VS2019打破了他们的曾经是std框架,但没人见过"的做法.现在将其命名为"pch",而不是"stdafx",这肯定是更明显的首字母缩写.只是名称更改,机制仍然相同.

UPDATE: after 28 years, Microsoft broken their "there used to be an std framework but nobody ever saw it" practices at VS2019. Now named "pch" instead of "stdafx", surely for the more obvious acronym. Just a name change, the mechanics are still the same.

这篇关于什么是在Visual Studio 2012中的新C ++项目中自动创建的stdafx.cpp文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆