Computer Help and Spyware Removal Computer Help and Spyware Removal Computer Help and Spyware Removal Computer Help Forums Windows Startup Programs Database Virus, Spyware, and Malware Removal Guides Computer Tutorials Uninstall Database File Database Computer Glossary Computer Resources
 

Welcome Guest ( Log In | Click here to Register a free account now! )



Register a free account to unlock additional features at BleepingComputer.com
Welcome to Bleeping Computer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.
Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.


 
Reply to this topicStart new topic
> C++ Unexpected End of File error
gnometorule
post Jun 13 2009, 01:31 PM
Post #1


New Member
*

Group: Members
Posts: 11
Joined: 25-January 09
Member No.: 287,251



Using Windows XP
Visual C++ Express 2008 (free version)

I get the following unexpected end of file message when entering code straight from the book "Exploring C++ / Ray Lischner" (email the author claims is his in the book doesn't exist, and there is no book web forum):

------ Build started: Project: ch39_1, Configuration: Debug Win32 ------
Compiling...
generate_id.cpp
c:\documents and settings\ralf becker.ralf_work\my documents\visual studio 2008\projects\c++\ch36_42\ch39_1\ch39_1\generate_id.hpp(14) : fatal error C1004: unexpected end-of-file found
main.cpp
c:\documents and settings\ralf becker.ralf_work\my documents\visual studio 2008\projects\c++\ch36_42\ch39_1\ch39_1\generate_id.hpp(14) : fatal error C1004: unexpected end-of-file found
Generating Code...
Build log was saved at "file://c:\Documents and Settings\Ralf Becker.RALF_WORK\My Documents\Visual Studio 2008\Projects\c++\ch36_42\ch39_1\ch39_1\Debug\BuildLog.htm"
ch39_1 - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

The code is as follows - a header file for a class; a .cpp file for the related member functions; and a main.cpp file (very short as just learning about concepts):

generate_id.hpp

#ifndef GENERATE_ID_HPP_
#define GENERATE_ID_HPP_

class generate_id
{
public:
generate_id() : counter_(0) {}
long next();
private:
short counter_;
static short prefix_;
static long int const max_counter_ = 32767;
};
#endif

generate_id.cpp

#include "generate_id.hpp"

short generate_id::prefix_(1);
long const generate_id::max_counter_;

long generate_id::next()
{
if (counter_ == max_counter_)
counter_ = 0;
else
++counter_;
return prefix_ * (max_counter_ + 1) + counter_;
}

main.cpp

#include <iostream>
#include <ostream>

#include "generate_id.hpp"

int main()
{
generate_id gen;
for (int i = 0; i!= 10; ++i)
std::cout << gen.next() << '\n';
}


I realize that typical solutions to this problem include:

(a) Check all braces etc. close properly, and
(\b) check if any precompiled headers are used (they are not - option is disabled).

I am obviously learning C++, so maybe this is just trival for you guys. What throws me off is that the program compiles and runs 100% fine if the pre-compiler commands #ifndef/#define/#endif are removed; output produced then is as expected:

32769
.
.
.
32778

So the error only starts when adding the precompiler #conditionals. However, the IDE recognizes the conditional proper, as witnessed by...

- producing a 'missing #endif' error if i remove #endif (just to check it), and
- by indicating that #endif corresponds to #ifndef in the usual IDE way (brief blinking of #ifndef after entering #endif)

Sorry for being verbose but meant to provide info as precisely as I could. Any help would be greatly appreciated. Throws me off quite a bit if i got trouble using such precompiler commands.

Best, OGtR.
Go to the top of the page
 
+Quote Post
gnometorule
post Jun 13 2009, 01:44 PM
Post #2


New Member
*

Group: Members
Posts: 11
Joined: 25-January 09
Member No.: 287,251



Issue resolved:

There needs to be a cr or similar after the #endif command. Once that is added, the program compiles fine. My apologies - might seem as if i didn't think about this before posting, which isn't true at all. Was stuck for hours but right after posting noticed. Best, O.
Go to the top of the page
 
+Quote Post
Billy O'Neal
post Jun 13 2009, 01:49 PM
Post #3


Look buddy -- I'm an Engineer
******

Group: Malware Response Instructor
Posts: 8,727
Joined: 17-January 08
From: Northfield, Ohio
Member No.: 184,215



Hello smile.gif

Assuming from the error code you're using a Microsoft compiler, see the following:
http://msdn.microsoft.com/en-us/library/4e...28VS.71%29.aspx

Is there a newline after the #endif in generate_id.hpp? Some compilers will choke if there's not one there.

EDIT: Looks like you beat me smile.gif

Billy3

This post has been edited by Billy O'Neal: Jun 13 2009, 01:51 PM


--------------------
The forum is always a busy place. In the event I fail to reply within twenty-four hours, feel free to send me a PM.
And that means I solve problems. Not problems like "What is beauty?" .. 'cause that would fall under the purview of your conundrums of philosophy....
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



Lo-Fi Version Time is now: 20th March 2010 - 01:23 AM


Advertise   |   About Us   |   Terms of Use   |   Privacy Policy   |   Contact Us   |   Site Map   |   Chat   |   Tutorials   |   Uninstall List
Discussion Forums   |   The Computer Glossary   |   Resources   |   RSS Feeds   |   Startups   |   The File Database   |   Virus Removal Guides

© 2003-2010 All Rights Reserved Bleeping Computer LLC.