Thread: stdafx.h (can't locate header file!)

  1. #1
    Registered User muffinman8641's Avatar
    Join Date
    Feb 2011
    Location
    Eastern-Central PA
    Posts
    76

    stdafx.h (can't locate header file!)

    So I copied and pasted a bit of the samegame code from your tutorials (which I love), and my compiler (which yes, is still DevC++, but will soon be Microsoft Visual Studio Professional) says that it can't find the stdafx.h header file. Perfectly understandable, but what to do now? Do I just copy-and-paste the source code and manually stick it in there?

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    stdafx.h is a precompiled header. It speeds up compilation.
    All it contains is a number of include statements. So remove that piece of code and add missing includes to your files as necessary to get it to compile. Hopefully, there should be no need to add any headers.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User muffinman8641's Avatar
    Join Date
    Feb 2011
    Location
    Eastern-Central PA
    Posts
    76
    So it's not actually required?

    Maybe this should get turned into a "muffinman8641's multitude of game programming questions" so I don't have to start a thousand new threads. :]

    I made a header file (as per the aforementioned tutorial's instructions) with this code:
    Code:
    #pragma once
    
    class CSameGameBoard
    {
    public:
      /*  Default Constructor */
      CSameGameBoard(void);
      /*  Destructor */
      ~CSameGameBoard(void);
      /*  Function to randomly setup the board */
      void SetupBoard(void);
      /*  Get the color at a particular location */
      COLORREF GetBoardSpace(int row, int col);
      /*  Accessor functions to get board size information */
      int GetWidth(void) const { return m_nWidth; }
      int GetHeight(void) const { return m_nHeight; }
      int GetColumns(void) const { return m_nColumns; }
      int GetRows(void) const { return m_nRows; }
      /*  Function to delete the board and free memory */
      void DeleteBoard(void);
    private:
      /*  Function to create the board and allocate memory */
      void CreateBoard(void);
      /*  2D array pointer */
      int** m_arrBoard;
      /*  List of colors, 0 is background and 1-3 are piece colors */
      COLORREF m_arrColors[4];
      /*  Board size information */
      int m_nColumns;
      int m_nRows;
      int m_nHeight;
      int m_nWidth;
    };
    ...and the file itself returns no errors. Problem is, the main project file says the header doesn't exist.
    Last edited by muffinman8641; 03-14-2011 at 08:57 AM.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It's not actually required, and any good programmer will make sure it compiles without it, since its only job is to speed up compilation.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User muffinman8641's Avatar
    Join Date
    Feb 2011
    Location
    Eastern-Central PA
    Posts
    76
    OK, another completely unrelated question: if I make a simple program that has an integer value that starts at 0 and increases by 1 each second, how can I get it to save this number like a saved score?

    Inspired by themostseconds.com type of scenario.

  6. #6
    Registered User muffinman8641's Avatar
    Join Date
    Feb 2011
    Location
    Eastern-Central PA
    Posts
    76
    A second question: I have this code:
    Code:
    if (list == 1) {
          ifstream inFile;
          inFile.open("seconds.exe");
           if(!inFile){ 
             cout << "Cannot open file.\n";
             getchar();
             return 1;
             }
             }
    for a program that leads to other programs. It runs ok but I enter the number one to open it and it just closes the program.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You might want to look over SourceForge.net: Pause console - cpwiki
    And indent properly, as well.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Registered User muffinman8641's Avatar
    Join Date
    Feb 2011
    Location
    Eastern-Central PA
    Posts
    76
    Thanks Elysia. You're a programming master! How the hell do you know every thing?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you help me about tolower() in file
    By nctar in forum C Programming
    Replies: 7
    Last Post: 05-12-2010, 10:04 AM
  2. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  3. Need help understanding Header Files
    By Kaidao in forum C++ Programming
    Replies: 11
    Last Post: 03-25-2008, 10:02 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Replies: 6
    Last Post: 04-02-2002, 05:46 AM