Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot open source file "stdafx.h"

Tags:

c++

visual-c++

I have two include file headers

#include "stdafx.h"
#include "psapi.h"

However it gives a cannot open source file "stdafx.h" compile time error. I am using Visual Studios 2010. Is "stdafx.h" even necessary? I think so because the program cannot compile if i take it away.

like image 353
Jake Avatar asked Jun 01 '11 14:06

Jake


People also ask

How do I open Stdafx H?

To turn it off, open the Visual C++ Component Properties dialog and in the tab "Includes" delete the text in the "Initial Source Includes". Another possibility is to create an empty "stdafx. h" file. For more information about precompiled header files, refer to the Microsoft knowledge base.

What is #include Stdafx h in C++?

"Stdafx. h" is a precompiled header.It include file for standard system include files and for project-specific include files that are used frequently but are changed infrequently. which reduces compile time and Unnecessary Processing.

What is PCH H in C++?

pch stands for precompiled header. In computer programming, a precompiled header is a (C or C++) header file that is compiled into an intermediate form that is faster to process for the compiler.

What is stdafx h in C++?

The file stdafx.h is usually used as a precompiled header file. Precompiled headers help to speed up compilation when a group of files in a project do not change.

Should all header files include stdafx h in Visual Studio 2010?

@Benoit: My Visual Studio (2010) reports something (at least a warning) when stdafx.h is not the first include. – Vlad Jun 1 '11 at 15:07 1 Note: if any onefile includes stdafx.h, then they all should. I had problems where only one file (from 3rd party) used it, so I had to include it in all my header files. I prefer not to use it.

How to turn off stdafx in Visual C++?

To turn it off, open the Visual C++ Component Properties dialog and in the tab "Includes" delete the text in the "Initial Source Includes". Another possibility is to create an empty "stdafx.h" file.

How do I add stdafx to my project?

The proper way of adding stdafx.h is by mentioning use pre-compiled header file in your Project settings. thank you so much ! it's all now clear to me ! You are welcome! No, it does not speed up the application, and it is not added by the compiler.


2 Answers

Visual Studio uses it for "precompiled headers" feature. If you are not experienced with Visual Studio, I would recommend to keep the stdafx.h in the project.

And of course, if you #include it, you ought to have it.

like image 135
Vlad Avatar answered Sep 22 '22 04:09

Vlad


stdafx.h is used for precompiled headers. It is not necessary, but disabling the compiler feature can be a little tricky if you have never done it before. If you have it, then you must compile 'stdafx.cpp' before compiling anything else.

like image 32
Blazes Avatar answered Sep 19 '22 04:09

Blazes