Getting Error - Regarding stdafx.h

I'm trying to fool around with the new Visual studio version (2005 Beta 2) and for some reason it keeps telling me:

\Practice.cpp(1) : fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory

A long time ago someone told me to go into the properties of the project and change the default to CLR support. I did this time but it doesn't seem to build.  Can someone tell me what to do   Here is my code:

#include "stdafx.h"

#using <mscorlib.dll>

using namespace System;

 

int _tmain()

{

int Number = 5, Number2 = 0, Number3 = 7;

int sum = 0;

Console::WriteLine("hello world.");

Console::WriteLine("Please enter a number.");

Number2 = Int32::Parse(Console::ReadLine());

sum = Number + Number2;

Console::WriteLine("The sum is: {0} {1}", sum, Number3);

return 0;

}




Answer this question

Getting Error - Regarding stdafx.h

  • theprogrammer

    HOw would I do that and Where should I store this file   Thank you for your help.

  • big71

    I just realized something,  I just noticed that I kept pressing "Empty Project."  Does this have something to do with all these errors   Because with I left it unchecked, this code automatically came up:

    // Hello.cpp : Defines the entry point for the console application.

    #include "stdafx.h"

    int _tmain(int argc, _TCHAR* argv[])

    {

    return 0;
    }

    What is that   is that what I"m supposed to get   because I typing #include "stdafx.h" manually.  what is
    int argc, _TCHAR* argv[]

    Also, I just tried not using the  Precompiled Headers, and it keeps giving me the same error message

    fatal error C1083: Cannot open include file: 'mscorlib.dll': No such file or directory


    What am I doing wrong



  • S&amp;#246;nmez

    The "Precompiled Header" is already checked, should I uncheck it



  • Chrisql

    The compiler is expecting to find the header stdafx.h in the project's directory. But as it is not finding it it is complaining.

    Probably making an empty file called stadfx.h would do the trick to get your compiler to stop complaining.

  • Pat Backowski

    I found this link

    http://msdn.microsoft.com/library/default.asp url=/library/en-us/vccore/html/vcurfprecompiledheaderfiles.asp

    hope it's useful

    Try linux. The folk are much more helpful.

    http://www.debian.org

  • hieronymus

    Adding the files themselves is not enough to enable a project to use precompiled headers.  I'm also not sure what you mean by "preloading" projects with precompiled headers.  I've helped another person on this issue by giving some basis for what pch files are and how they're created.  Perhaps reading my previous post will help demystify the issues.
      
    http://forums.microsoft.com/msdn/ShowPost.aspx PostID=115695


  • http200

    If you want precompiled headers, it should be checked. 
  • Igor Tur

    You need to do project->properties then select c++ tab and select precompiled headeers. Inn the dropbox you need to select no precompiled headers rather than the default /Yu. After which you need to delete the #include "stdafx.h" and then everything works fine.

    Alternatively, if you wich to keep the precompiled headers turned on you need to go into the stdafx.h file and under where it says ~TODO you need to include the headers which are caussing  errors to be thrown. Then everythingworks great. I had exactly the same problem.

  • Stan Burton

    LOL, THanks again, yeah I read it, and what I meant by "pre-load" is when you choose a template such as Win32 Console APP, it loads, as I saw in the 2003 VS studio, specific files, such ast he stdafx.h, stdafx.cpp were already loaded into the project.  I think when I choose a template (project type), I would choose "CLR CONSOLE APP" if I want to use the Console::WriteLIne() to print onto the command screen.  That is what I did, I chose CLR Console App and did the Console::WriteLine("Hello!") and it worked find.  When I chose Win32, and did the same thing it wouldn't work.  I did as you said and did that /n thing but it didn't let me create the stdafx.cpp file or stdafx.h file.  THis whole new type of source code is very new to me.

  • giantpanda77

    Now I'm confused, I deleted <mscorlib.dll> and it actually executes, displaying "Hello!".  why is this happening

  • Roil_O

    I just realized, are you using VS C++ 2003 OR 2005  Because In 2003, you can use the win32 template and use the managed code but in the Win32 in 2005 you can't.  I think the reason why is because 2003 has Win32.NET and 2005 doesn't.  I've already tried unchecking the precompiled headers box and changing the properties to accept CLR but it still doesn't work, keeps bringing up an error saying, Debug/[Project name].pch doesn't exist.  So my only real conclusion is that the only way to do it using this type of code is to use the "CLR Console "Empty" Application."  I tried it and it actually executes. 

    #include "stdafx.h"
    #include <mscorlib.dll>
    using namespace System;

    int _tmain()
    {

    Consol::WriteLine("Hello World!!");
    return 0;
    }

  • jornjorn

    Ask Linux about Visual Studio 2005 beta 2

    THis is driving me crazy because I had this same problem with the 2002 version, and I can't program because of this.

    I tried what you said but the 2005 beta already has the precompiled header set to "OFF", and Ctrl N brings up the ADD NEW ITEM DIALOG BOX. 

    Also what I did was in my first project titled "John" I looked in the folder and found several more files that pre-loaded into the project: here are the files that preloaded into that project that WILL NOT load into the other ones:

    stdafx.h (source file)
    stdafx C/C++ (header file)
    Readme.txt (explaining the folders contents

    what I did was copied the stdafx source and header files into the projects that wouldn't work.  It actually worked, so what I'm trying to figure out is how to program VS to pre-load the stdafx source and header file into each project.  Any ideas

    **updated**
    I found that in order for it to work I have to choose CLR Console "Empty Project."

  • ashish_2060

    If I understand you correctly, creating a new Win32 Console Project does not give you stdafx.cpp and stdafx.h.  Did you check the "Precompiled Header" setting under the Application Settings page prior to pressing Finish

    The "\n thing" was an entirely different issue that was piggybacking on that thread--you can ignore that.

    Brian

  • Carlos Hdez

    You would press ctrl N for new and then name the file stdafx.h and place it in the directroy of your project.

    But then, as I have you would probably run into all kinds of other problems.

    Do project=>properities and then select the C++ folder

    This opens up a dialog with the project settings. Your objective is to disable the precompiler.
    The top row in the dialog at the right (in VS.net 2003) is the one you are interested in. Click on the row to open a drop down box and select no precompiler.

    Then delete the include stdafx.h file and you're away. Let me know if this works for you.

    It seems that stdafx.h is a way of gathering the includes that your project needs and precompiling them. I've had nothing but trouble with it and found documentation lacking on the subject. I would just turn it off until you think you need it.

  • Getting Error - Regarding stdafx.h