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?
答案 0 :(得分:8)
#include
语句有三种形式。
# include "h-char-sequence" new-line
# include <h-char-sequence> new-line
# include pp-tokens new-line
其中pp-tokens
必须扩展为前两种形式之一。
您可以使用:
#include IOSTREAM
并使用-DIOSTREAM="<iostream>"
或-DIOSTREAM="<iostream.h>"
进行编译,具体取决于您使用的编译器版本。
但是,你不能使用
#include <iostream.h>
并使用-Diostream.h=iostream
进行编译。
这有几个问题。
iostream.h
不是有效的预处理器宏。#include
语句的形式不适合宏扩展。如果您已准备好迁移代码库以使用新的C ++标头,那么最好使用您喜欢的脚本方法将所有旧式C ++标头更改为新的C ++标头。