Jump to content

Recommended Posts

Posted

I have encountered problem when trying to include fstream into one of my header classes. Visual Studio 2013 express gives my immediately this error:

C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\fstream(39): error C2065: 'EOF' : undeclared identifier

 

At first I thought it might be a bug with VS but then I found FileSystem::ReadFile as method of reading the file. But still if for reason <input here> that I would like to use fstream, how would I do that?

 

Do I need to rewrite every files in my project that use fstream? Not that's a problem just curious.

 

Still not sure if this is a bug or intended.

Posted

The quick answer--you can add this to the appropriate .h file before including fstream:

 

const char EOF = -1;

 

EOF is defined (IIRC) in stdio.h as -1, but if you're not including that then you can define it yourself...

--"There is no spoon"

Posted

The problem is that in the files Stream.h and BankStream.h (from Leadwerks), EOF is explicitly undefined via

#undef EOF

because they have a method using this name.

 

Including fstream before leadwerks fixes the problem, since the compiler first has EOF defined, when he reaches fstream and then, when going through the Leadwerks-Includes, it can be undefined. Also because EOF is a compiler-variable, I would prefer this method to the one Michael_J proposed.

If you want to use EOF in your own code you will have to define it yourself, though (so you could just do both).

  • Upvote 1
Posted

Okay I did thought fstream was self contained as I don't have this problem with other projects (not LE based). Thanks for clearing this issue, I am sure this might be handy for other as well.

Thank you!

Posted

The problem is that in the files Stream.h and BankStream.h (from Leadwerks), EOF is explicitly undefined via

#undef EOF

because they have a method using this name.

 

Including fstream before leadwerks fixes the problem, since the compiler first has EOF defined, when he reaches fstream and then, when going through the Leadwerks-Includes, it can be undefined. Also because EOF is a compiler-variable, I would prefer this method to the one Michael_J proposed.

If you want to use EOF in your own code you will have to define it yourself, though (so you could just do both).

 

That clears things up a bit--never actually had time to investigate WHY EOF wasn't defined. Good to know...

--"There is no spoon"

  • 7 years later...
Posted

This is Microsoft's fault. It's a bad idea to use macros to define variables because they do not allow for a namespace, which causes conflicts with other code. Enums are the best for this because they can be used with switch statements and can be compartmentalized in a namespace.

Let's build cool stuff and have fun. :)

Posted

It looks like in stdio.h EOF is defined as follows:

#define EOF    (-1)

It looks like it is just a constant value -1. If so, you can just take that definition and place it directly before you include fstream.h. Keep in mind this value could be different on some systems.

#ifdef _WIN32
	#define EOF    (-1)
#endif
#include <fstream.h>
#undef EOF

 

Let's build cool stuff and have fun. :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...