我正在尝试在 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;
我该如何解决这个问题?
原文由 subodh1989 发布,翻译遵循 CC BY-SA 4.0 许可协议
你可以
#include <strstream>
(注意没有’.h’后缀)。但是,如果您想将代码正确地移植到现代 C++,您应该考虑将其更改为#include <sstream>
和std::ostringstream strDestXML;
如评论中所建议的那样。