?
Solved

unexpected end of file in vc++

Posted on 2003-03-09
4
Medium Priority
?
358 Views
Last Modified: 2008-03-17
for some reason whenever i have a project with the following i get an error...

the main .cpp file
a .h header file (doesnt matter how many)
a coresponding .cpp source file (for each header file, each header file contains the declaration of a class)

it only happens when i have the files included in the project itself, naturaly they are #included in the files themselves... but if i leave it as just that and dont keep them in the project i get no errors...

to test this out i made the following

//main.cpp
#include "StdAfx.cpp"
#include <iostream>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
#include "bungo.h"

using namespace std;

void main()
{
    bungo moo;
    while(!_kbhit())
    {
        moo.randomize();
        cout << "mooooo! " << moo.b << "\r";
        Sleep(500);
    }

    getch();

    cout << endl;
}

//bungo.h

#ifndef _bungo_h
#define _bungo_h

#include <iostream>
#include <stdlib.h>
#include <windows.h>

class bungo
{
    public:
        bungo();
        ~bungo();
        void randomize();
        int b;
};

#include "bungo.cpp"

#endif

//bungo.cpp
#ifndef _bungo_cpp
#define _bungo_cpp

#include "bungo.h"

bungo::bungo()
{
    b=0;
}

bungo::~bungo()
{
    cout << "bye!" << endl;
}

void bungo::randomize()
{
    b=rand();
}

#endif


and for some reason i get this error (that points to the end of bungo.cpp

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


normaly that means a mismatched bracket or something somewhere, but im 100% sure i matched them all (cause this happens in all projects i create). i honestly i am at a loss here. cause it works fine if i dont include the files in the project. id like them in the project cause it lets me use the class view thing which makes keeping track of all the classes i have easier (for a big thing im working on its almost a necessity, but it wont compile and link if i got it so that the files are in the project).
0
Comment
Question by:BungoMan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
Kocil earned 100 total points
ID: 8099187
At the header

#ifndef _bungo_h
#define _bungo_h

class bungo
{
};

//********* remove this
//#include "bungo.cpp"

#endif

At the CPP you dont need include safety

//bungo.cpp
//******* remove this
//#ifndef _bungo_cpp
//#define _bungo_cpp

#include "bungo.h"

bungo::bungo(){}
bungo::~bungo(){}
void bungo::randomize(){}

//****** and also this
//#endif

0
 
LVL 15

Expert Comment

by:efn
ID: 8099188
Most likely, this is what's happening:

In the Project Settings, on the C++ tab, in the Precompiled Headers category, there are some radio buttons specifying whether to use precompiled headers.  You are probably getting, by default, the setting "Use precompiled header file (.pch) Through header stdafx.h."  That means you are promising the compiler that the file will #include the stdafx.h header file, and the error messages mean that this promise was not kept.

To get rid of the errors, you can either #include this file, if you have a suitable one, or change the Precompiled Headers radio button settings for all the files that generate errors.  You can safely set them to "Not using precompiled headers."  Precompiled headers don't do anything for you functionally, they just make compilation faster.

It might be something else in your case, but in my experience, this is what has caused these error messages.

--efn
0
 
LVL 5

Expert Comment

by:Kocil
ID: 8099199
And also I wonder about this

//main.cpp
//****** why do you include a CPP ?
//****** should be NOT
#include "StdAfx.cpp"

#include <iostream>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
#include "bungo.h"
0
 

Author Comment

by:BungoMan
ID: 8101105
bah i fixed it all, youre right about the protection in the cpp files lol. im such a dork... seemed to help to make a new project too, one without the precompiled stuff. now to solve the errors in my vector stuff...
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question