Error Cannot Open Source File Stdafx.h
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Error C1083: Cannot open include file: 'stdafx.h' up vote 5 down vote favorite When I compiled this program (from Programmin Launguage 4th edition): main.cpp #include
SQL Server 2014 Express resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards Events Community Magazine Forums Blogs Channel 9 Documentation APIs and reference Dev centers Retired content Samples We’re sorry. The content you requested has been removed. You’ll be auto redirected in 1 second. Ask a question Quick access Forums home Browse forums users FAQ Search related threads Remove From My Forums Asked by: Error: Cannot open source file "StdAfx.h" (Intellisense) Archived Forums V > Visual C++ IDE Question 1 Sign in http://stackoverflow.com/questions/26330178/error-c1083-cannot-open-include-file-stdafx-h to vote I am trying a test port of a VC++ project (ATL/WTL) from VC2005 to the 2010 release candidate. On opening some of my source files in the code editor I noticed a large number of Intellisense red error "squiggles" the first of which is "Error Cannot open source file "StdAfx.h"". The rest of them seem to be due to https://social.msdn.microsoft.com/Forums/en-US/efdf4ae8-437d-4a7f-8cf5-b895257da2bd/error-cannot-open-source-file-stdafxh-intellisense?forum=vcprerelease missing pre-compiled header symbols as would be expected. However dispite this the project builds and runs without any problem, so the compiler can find the precompiled header, but Intellisense cannot! I discovered that the files effected were all in a subdirectory off the main source directory. I tried replacing "#include "stdafx.h" with "#include "..\stdafx.h". This fixed the intellisense problem but now the file will not compile: Error6error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source? This after a number of warning C4627 including for "..\stdafx.h" (skipped when looking for precompiled header use). So it seems that Intellisense and the compiler use different search rules when looking for header files and that the compiler will only recognise the pre-compiled header file if it is specified exactly without a path. I did find a work-round for this bug: have two include lines as follows: #include "stdafx.h" #include "..\stdafx.h" Now both Intellisense and compiler work, with just the one Intellisense error squiggle under the first #include. Please let me know if there is
tutorial I hit a snag. In the tutorial 0.6 it clearly states: Important note http://www.cplusplus.com/forum/beginner/39659/ to Visual Studio users: Visual studio programs should ALWAYS begin with the following line: #include "stdafx.h" When I do that on the Hello World program I get the http://www.codeproject.com/Questions/1131539/Cplusplus-error-cannot-open-source-file-stdafx-h following error: Code: 1
2
3
4
5
6
7
8
9
10
11
1>Build started 3/29/2011 2:18:18 PM. 1>InitializeBuildStatus: 1> Touching "Debug\HelloWorld.unsuccessfulbuild". 1>ClCompile: 1> Helloworld.cpp 1>c:\users\jon\documents\visual studio 2010\projects\helloworld\helloworld\helloworld.cpp(2): fatal error C1083: Cannot open include file: 'stdafx.h': No error cannot such file or directory 1> 1>Build FAILED. 1> 1>Time Elapsed 00:00:00.25 ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== If I build or Run [Without Debugging], leaving out #include "stdafx.h" it works fine. I know since I got it working, It shouldn't matter, but its bugging me and I have a feeling error cannot open it might trip me up later if I don't know. Thanks in advance! Scibat Mar 30, 2011 at 5:55pm UTC Disch (13766) Important note to Visual Studio users: Visual studio programs should ALWAYS begin with the following line: That tutorial is wrong. You only need stdafx.h if you make a project that has some prebuilt settings. If you choose to make an empty project with VS, you don't need it. In your case, try removing it. Mar 30, 2011 at 6:32pm UTC scibat (2) I guess I'll figure out when I need it and when I don't later on as I learn. Thanks for the help! Mar 30, 2011 at 7:21pm UTC Disch (13766) You only need it when MSVS gives it to you. If you make a blank project that starts with no cpp files, you don't need it. Usually when you DO need it, VS will give you a cpp file that already has the #include "stdafx.h" line at the time. Top
Tips/Tricks Top Articles Beginner Articles Technical Blogs Posting/Update Guidelines Article Help Forum Article Competition Submit an article or tip Post your Blog quick answersQ&A Ask a Question View Unanswered Questions View All Questions... C# questions Linux questions ASP.NET questions SQL questions VB.NET questions discussionsforums All Message Boards... Application Lifecycle> Running a Business Sales / Marketing Collaboration / Beta Testing Work Issues Design and Architecture ASP.NET JavaScript C / C++ / MFC> ATL / WTL / STL Managed C++/CLI C# Free Tools Objective-C and Swift Database Hardware & Devices> System Admin Hosting and Servers Java .NET Framework Android iOS Mobile SharePoint Silverlight / WPF Visual Basic Web Development Site Bugs / Suggestions Spam and Abuse Watch features Competitions News The Insider Newsletter The Daily Build Newsletter Newsletter archive Surveys Product Showcase Research Library CodeProject Stuff communitylounge Who's Who Most Valuable Professionals The Lounge The Insider News The Weird & The Wonderful The Soapbox Press Releases Non-English Language > General Indian Topics General Chinese Topics help What is 'CodeProject'? General FAQ Ask a Question Bugs and Suggestions Article Help Forum Site Map Advertise with us About our Advertising Employment Opportunities About Us Ask a Question All Questions All Unanswered FAQ C++ error: cannot open source file "stdafx.h" Rate this: Please Sign up or sign in to vote. See more: C++ Errors I started a new EMPTY project on visual studio and when I wrote #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 24-Sep-16 3:36am Ruba Sh356 Updated 27-Sep-16 1:55am Add a Solution