error C1010: unexpected end of file while looking for precompiled header.

This is a discussion on error C1010: unexpected end of file while looking for precompiled header. within the C++ Programming forums, part of the General Programming Boards category; Hello!I tried out a program on constructors in VC++ 2008 Express Edition and Turbo C++.On compilation both of them showed ...

  1. #1
    Registered User
    Join Date
    Aug 2007
    Location
    INDIA
    Posts
    13

    error C1010: unexpected end of file while looking for precompiled header.

    Hello!I tried out a program on constructors in VC++ 2008 Express Edition and Turbo C++.On compilation both of them showed 0 errors and 0 warnings.But while running the program VC++ showed:
    "fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?" and failed to run.But Turbo C++ ran the program smoothly and showed the output. Could any one tell me what's the reason behind and how to fix the problem?
    My code in VC++:

    Code:
    #include"stdafx.h"
    #include <iostream>
    using namespace std;
    
    class integer
    {
    	int m,n;
    public:
    	integer(int,int);
    	void disp(void)
    	{
    		cout<<m<<" "<<n;
    	}
    };
    integer::integer(int x, int y)
    {
    	m=x;
    	n=y;
    }
    int main()
    {
    integer int1(0,100);
    
    integer int2=integer(25,75);
    cout<<"\nOBJECT1"<<endl;
    int1.disp();
    
    cout<<"\nOBJECT2"<<endl;
    int2.disp();
    
    return 0;
    }

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Go into your project settings, C/C++ Compiler, Precompiled headers, and set it to "No precompiled headers" (you may have to use some fuzzy logic to get there, but I'm pretty sure I'm close).

    [I also think that if, when you create a project, you select "Empty project" it will automatically select precompiled headers as off, but I'm not sure].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Aug 2007
    Location
    INDIA
    Posts
    13
    Thanks! the first solution didn't work But the second one worked...

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by paushali View Post
    Thanks! the first solution didn't work But the second one worked...
    I'm sure there is a way to do the first one too - but as long as you have a solution, that'll do, I guess.

    [Precompiled headers should really be turned off by default, they only really make sense for LARGE projects, and if you work on a large project, you probably know how to select precompiled headers, so it's just silly to have it on by default].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,438
    Quote Originally Posted by paushali View Post
    Thanks! the first solution didn't work But the second one worked...
    Following the first solution matsp presented you, you must also delete the line including stdafx.h
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  6. #6
    Registered User
    Join Date
    Aug 2007
    Location
    INDIA
    Posts
    13
    Following the first solution matsp presented you, you must also delete the line including stdafx.h
    Actually I had also deleted the line containing stdafx.h but when I tried to run the program I got the following errors:
    1."stdafx.obj : error LNK2005: "public: __thiscall integer::integer(int,int)" (??0integer@@QAE@HH@Z) already defined in constructor.obj"
    2."stdafx.obj : error LNK2005: _main already defined in constructor.obj"
    3."C:\Documents and Settings\Dr. D.K.Kundu\My Documents\Visual Studio 2008\Projects\constructor\Debug\constructor.exe : fatal error LNK1169: one or more multiply defined symbols found"

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    That sounds like you've got implementations in headers.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,548
    You mean you got those errors with or without stdafx.h and mats's solution?
    To clarify:
    All implementation should be done in source files (.cpp) and class definitions only should be in 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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  2. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 09:46 AM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21