使用 #include < iostream.h>

Use of #include <iostream.h>

本文关键字:gt iostream lt #include 使用      更新时间:2023-10-16

我正在做一个旧的项目,它仍然有不推荐的"#include iostream.h"包含。我知道iostream.h已被弃用,不应该使用,但是这段代码必须在一些运行CC的旧solaris机器上运行/编译,并且没有iostream可用。我的问题是:我怎样才能使我的更现代的c++编译器接受iostream.h的包含。

编辑:编译器找不到iostream.h文件,所以我假设没有。h版本的库可用于g++。

最简单的解决方案可能是创建一个名为iostream.h的本地头文件,该文件仅包含<iostream>并导入命名空间std。然后,为了使编译器允许#include <iostream.h>,您将本地路径添加到包含文件搜索路径中。对于g++,这可以工作:

g++ -I local_folder [other flags] …
顺便提一下,你对 的评论

…弃用的"#include iostream.h"

是不完全正确的:这并没有被弃用,因为它从来不是合法的c++。

我会退一步,写另一个你在任何地方使用的中间头,而不是像这样:

#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