I'm working with some old C++ code that, apparently, pre-dates the standardization and move from iostream.h
to iostream
, and similarly for other includes. Consequently, my relatively modern version of g++ fails when trying to #include <iostream.h>
, etc.
I'm curious if it's possible to use the preprocessor to change instances of iostream.h
to just iostream
, via the command line. I've tried appending -Diostream.h=iostream
to g++, but that doesn't seem to alter the include statements.
I'm guessing it's not possible for the preprocessor to modify include statements?
There are three forms of the #include
statement.
# include "h-char-sequence" new-line
# include <h-char-sequence> new-line
# include pp-tokens new-line
where pp-tokens
must expand to one of the first two forms.
You could use:
#include IOSTREAM
and compile with -DIOSTREAM="<iostream>"
or -DIOSTREAM="<iostream.h>"
depending on the version of compiler you are working with.
However, you can't use
#include <iostream.h>
and compile with -Diostream.h=iostream
.
There are couple of problems with that.
iostream.h
is not a valid preprocessor macro.#include
statement is not appropriate for macro expansion.If you are ready to migrate your code base to use the new C++ headers, you will be better off using your favorite scripting method to change all the old style C++ headers to new C++ headers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With