Thread: Stdafx.h?

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    195

    Stdafx.h?

    I really have no clue what this header file does, can someone please explain? Also where do you get it?

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    It's needed in MSVC++. Not really a standard header file.

  3. #3
    *******argv[] - hu? darksaidin's Avatar
    Join Date
    Jul 2003
    Posts
    314
    stdafx.h is also used in the open GL tutorial for SetTextColor and TextOutA.
    Where do I find those functions in standard C? (I'm using mingw on dev cpp)

  4. #4
    Registered User Casey's Avatar
    Join Date
    Jun 2003
    Posts
    47
    >>Where do I find those functions in standard C?
    You don't because they're not standard functions.

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    stdafx header file contains prewritten code to set up the console window you use when writing code with MSVC. This allows you to enlarge the console window, scroll the console window, etc., all of which isn't possible in formats such as Dev-C++, Borland, etc., without you adding the necessary code from the underlying Windows API.

  6. #6
    *******argv[] - hu? darksaidin's Avatar
    Join Date
    Jul 2003
    Posts
    314
    Originally posted by Casey
    >>Where do I find those functions in standard C?
    You don't because they're not standard functions.


    So how do you output anything to a window at all in standard C++ then ? Only through windows controls ?

    edit: ok, thanks elad. Guess this tutorial isn't for me than
    Last edited by darksaidin; 07-21-2003 at 07:36 AM.

  7. #7
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    Hold on. Don't run away or throw away the tutorial. It's just that things aren't as simple as they could be. You can write all the standard C++ code you want using MSVC. It will compile fine with other MSVC compilers and if the other programmer isn't using MSVC they just comment out the stdafx header file. In fact, once you list the stadafx file in the list of includes you can almost forget you are using MSVC and pretend you are using a "pure" C++ compiler. Problem is there is no "pure" C++ compiler. They all have their quirks. You learn to work around them. And yes, there can be problems with portability, so sticking with a given compiler and using it without consideration of porting it or sticking to standard C++ as much as possible is the key.

    If you don't know already, there is a difference in how you write code to output material on the screen using console/DOS vs using Windows. In console/DOS mode you use cout (for C++) or printf() (for C) (in reality you can use printf() in C++ too, but you can't use cout in C). In Windows you have to use Text output functions that are event driven, even though the Windows API is written in C/C++. stdafx contains the magic that allows you to use cout or printf() to display output on the screen without having to use the Text output functions or other output functions in the Windows API itself. For now, don't worry about what's in the "magic box". Just use it. You can draw back the curtain to see the wizard later in your career.

  8. #8
    *******argv[] - hu? darksaidin's Avatar
    Join Date
    Jul 2003
    Posts
    314
    Point is I'm new to C. I used to code with Delphi but I was pretty much tired of header translation (whenever something new is released, headers are for C and not for OP/Delphi). That was the only reason to switch to C in the first place. Now that I come to find the same problem here, I could as well go back to Delphi. At least there it's not the Delphi code that is not running but "only" some Headers I got to translate

    Anyway, I just skipped that part of the tutorial. Now I got a different problem, but maybe I'll find the sollution somewhere here on the board (search button, fear me! )...

  9. #9
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    You can turn off stdafx.h if you want. stdafx.h doesn't actually contain anything more than #includes of other headers. The idea is that you put very widely used headers that won't change in stdafx.h, and they are precompiled.

    All it does is make builds faster. It's not even needed in VC++ if you turn precompiled headers off.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. doesn't recognize stdafx.h
    By GiantFurby in forum C++ Programming
    Replies: 4
    Last Post: 03-24-2009, 10:42 AM
  2. stdafx.h and the FreeType library
    By Mastadex in forum Windows Programming
    Replies: 1
    Last Post: 11-23-2007, 01:36 PM
  3. stdafx.h
    By beene in forum Windows Programming
    Replies: 7
    Last Post: 10-15-2006, 10:25 AM
  4. stdafx.h question
    By ssjnamek in forum C++ Programming
    Replies: 5
    Last Post: 08-12-2005, 11:31 PM
  5. stdafx.h
    By HQSneaker in forum Windows Programming
    Replies: 10
    Last Post: 08-13-2004, 12:19 PM