Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Recommended Posts

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.

Link to post
Share on other sites

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
Link to post
Share on other sites

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!

Link to post
Share on other sites

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...

Link to post
Share on other sites
  • 7 years later...

This is pretty bad from user experience point of view.

Really don't want to deal with this kind of things, the standard headers should work out of the box.

Having same problem with UAK.

Link to post
Share on other sites

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.

Link to post
Share on other sites

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

 

Link to post
Share on other sites

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...