3

I am working on an older project that still has the deprecated "#include iostream.h" inclusions. I understand that iostream.h is deprecated and should not be used, but some of the systems that this code has to run/compile on are old solaris machines running CC and do not have iostream available. My question is: how can I make my more modern g++ compiler accept the iostream.h inclusions.

EDIT: The compilier cannot find the iostream.h file so I am assuming that none of the .h versions of the library are available to g++.

9
  • is the -std=c++98 flag an option?
    – Andy Prowl
    Jan 17, 2013 at 20:26
  • 4
    @Andy does that work? iostream.h was never in the C++98 standard. Jan 17, 2013 at 20:29
  • @KonradRudolph: not sure, I am not familiar with these old headers, i just thought the older standard might have supported them and provided a hint. it might well be wrong
    – Andy Prowl
    Jan 17, 2013 at 20:32
  • @AndyProwl: Certainly doesn't work for me (g++ 4.7.2)
    – NPE
    Jan 17, 2013 at 20:32
  • 6
    iostream.h is not deprecated. it has never been standard, so it's impossible to deprecate. it's a pre-standard header. Jan 17, 2013 at 20:36

2 Answers 2

5

The easiest solution is probably to create a local header file called iostream.h which just includes <iostream> and imports the namespace std. Then, in order for the compiler to allow #include <iostream.h> you add the local path to your include file search path. For g++, this works:

g++ -I local_folder [other flags] …

Incidentally, your remark about

… the deprecated "#include iostream.h"

isn’t quite correct: this isn’t deprecated because it has never been legal C++.

5
  • But doesn't '<iostream>' require a std namespace? Jan 17, 2013 at 20:31
  • You probably want it to do #include <iostream>\nusing namespace std; to have some hope of the code compiling/working. Jan 17, 2013 at 20:34
  • @Matt I wasn’t sure so I kept my answer intentionally vague. Just add the using namespace std; then. Jan 17, 2013 at 20:35
  • +1 this is a good answer. but please add information about the OP's erroneous claims about deprecation. it would be bad for SO to serve as a means of propagating such misconceptions. Jan 17, 2013 at 20:38
  • @Cheersandhth.-Alf Well I actually think that your comment on the question is a much better place to admonish that but I’ve added it for what it’s worth. Jan 17, 2013 at 20:43
4

I'd take a step back and write another intermediate header you use everywhere instead that does something like:

#if defined(sun) || defined(__sun)
# if defined(__SVR4) || defined(__svr4__)
/* Solaris */
#include <iostream>
# else
/* SunOS */
#include "iostream.h"
# endif
#else
/* Sane, modern system */
#include <iostream>
#endif
3
  • That was my thought as well, IM just not sure how to handle the namespace issue since the old SunOS doesnt understand namespaces. Modify that intermediate to include a "using namespace std" on places where iostream is defined? Jan 17, 2013 at 20:37
  • 1
    -1 this is an ungood answer, in that system-detection for C and C++ is just as extraordinarily bad as browser detection for web pages. unless you're in the business of doing platform adaption, like boost. Jan 17, 2013 at 20:42
  • 1
    @Cheersandhth.-Alf - I would suggest feature detection instead of system detection, but short of switching to autotools that's not really viable (and autotools on old solaris is a PITA still)
    – Flexo
    Jan 17, 2013 at 21:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.