Vulcan Posted July 8, 2014 Share Posted July 8, 2014 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. Quote Link to comment Share on other sites More sharing options...
Michael_J Posted July 8, 2014 Share Posted July 8, 2014 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... Quote --"There is no spoon" Link to comment Share on other sites More sharing options...
Ma-Shell Posted July 8, 2014 Share Posted July 8, 2014 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). 1 Quote Link to comment Share on other sites More sharing options...
Vulcan Posted July 8, 2014 Author Share Posted July 8, 2014 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! Quote Link to comment Share on other sites More sharing options...
Michael_J Posted July 8, 2014 Share Posted July 8, 2014 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... Quote --"There is no spoon" Link to comment Share on other sites More sharing options...
aiaf Posted July 9, 2021 Share Posted July 9, 2021 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. Quote I made this with Leadwerks/UAK: Structura | Stacky Desktop Edition Website: Binary Station Link to comment Share on other sites More sharing options...
Josh Posted July 9, 2021 Share Posted July 9, 2021 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. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Josh Posted July 10, 2021 Share Posted July 10, 2021 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 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Recommended Posts
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.