Click here to Skip to main content
15,039,244 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I started a new EMPTY project on visual studio and when I wrote
C++
#include "stdafx.h"

it gave me an error : cannot open source file "stdafx.h"

What I have tried:

so I went to Header Files -> Open -> existing Item -> and opened stdfax.h from another project but still , it gave me the same error . anyone can help ?
Posted
Updated 18-Nov-20 13:35pm

To my knowledge it a pre-compiled header file, It helps in speeding up the C++ application. Notice the double quotes "" over there that means it is a user added header file generally headers will be in <> and for user added header file #include"location of the header file" stdafx is generally added by the compiler in a default project location and for an empty project the compiler wont create any files at all so you need to add New Item(Header file) with the name of stdafx.h to make the application work for you. Remember this will not speed up the C++ application.


The proper way of adding stdafx.h is by mentioning use pre-compiled header file in your Project settings.


Feel free to ask any doubts
   
Comments
Member.R 2-Oct-16 8:51am
   
thank you so much ! it's all now clear to me !
[no name] 2-Oct-16 9:43am
   
You are welcome!
Richard MacCutchan 2-Oct-16 9:49am
   
No, it does not speed up the application, and it is not added by the compiler.
[no name] 3-Oct-16 14:02pm
   
Sir, To my knowledge precompiled header file will not be compiled every-time so that will speed up the compiling process. Sorry sir I have posted as speeding application and it is still to my knowledge I don't know whether this is correct or not I mean it will speed up compilation time or not. And could you please give the correct answer for second one it is Visual Studio or something which adds this? Thank you for your time sir. I am sorry for providing wrong information
Richard MacCutchan 4-Oct-16 4:03am
   
Yes it can speed up the compilation process, but with the speed of modern computers that is rarely an issue. And no, it will not speed up the actual application, since the generated code will be the same whether you use precompiled headers or not. As I stated in my response above the stdafx.h (and its corresponding .cpp) file(s) are generated by the New Project Wizard, which is part of Visual Studio, not the compiler.
That file is generated automatically by the New Project wizard, and is used by the compiler to build the pre-compiled headers file. In an empty project it will not exist.
   
Comments
Member.R 2-Oct-16 8:50am
   
thanks
please show your code..

I think you have defined #include"afxwin.h" thats why your getting error.

you should define in "afxwin.h" instead of
   
v2
Comments
Member.R 2-Oct-16 8:47am
   
Oh thanks ! it worked ^_^
Member 14781922 12-May-20 8:37am
   
Question text
Write C++ code for a function called min(). This function takes two floating parameters num1 and num2 and returns the minimum between the two.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900