错误: strstream.h: 没有这样的文件或目录

error: strstream.h: No such file or directory

本文关键字:文件 strstream 错误      更新时间:2023-10-16

我正在尝试在Linux(Redhat)中运行旧的C++代码。我正在使用 gcc 版本 4.1.2。

我收到以下错误:

error: strstream.h: No such file or directory
/trnuser1/rmtrain/DevelopmentEnv/Generic/CoreObjects/GCVTransformationServices.cpp:41: error: âostrstreamâ was not declared in this scope
/trnuser1/rmtrain/DevelopmentEnv/Generic/CoreObjects/GCVTransformationServices.cpp:41: error: expected `;' before âstrDestXMLâ
/trnuser1/rmtrain/DevelopmentEnv/Generic/CoreObjects/GCVTransformationServices.cpp:62: error: âstrDestXMLâ was not declared in this scope

此代码在 gcc 版本 2.95 的 Solaris 下运行良好。错误指向的行包含以下语句:

ostrstream strDestXML;

我该如何解决这个问题?

你可以

#include <strstream>(注意没有'.h'后缀)。但是,如果要将代码正确移植到新式C++,则应考虑将其更改为注释中建议的#include <sstream>std::ostringstream strDestXML;

标准C++标头没有扩展名。

#include <sstream>

标准类包含在std命名空间中:

std::ostringstream strDestXML;

最后,strstream被弃用;改用stringstream - 这就是我在这里使用它的原因。


而且,只是关于 GCC 版本的注释 - 4.1.2 是旧的,无论如何 - 使用更新的东西。

此包含的现代名称是 <strstream> 。 (尽管它已正式弃用,但仍是必需的。 它定义的类在命名空间std中,并且语义与经典的iostream略有不同,因此您以后可能需要进行一些修改。 (根据它的使用方式,更改为 <sstream> ,用 std::[io]stringstream 替换[io]strstream可能是有意义的。