C++运算符<<调用::ostream而不是std::osttream

C++ operator << calling ::ostream instead of std::ostream

本文关键字:lt osttream std C++ 调用 运算符 ostream      更新时间:2023-10-16

我已经搜索了很多次,但都没有找到答案,所以如果这是重复的,请原谅。

我有一些非常古老的C++代码,我正试图将它们轻松地转换为这个千年。代码仍然在Visual Studio 6中编译,并且需要继续这样做,但我也在努力让它在Visual Studio 2017中运行。我以前也这样做过,但对头文件等进行了许多更改,这次我尝试了一种更谨慎的方法。

该代码已经混合使用了stl和非stl、旧的和新的io头等等,所以它是一个等待爆炸的烂摊子。

作为一个简单的开始,我只是用iostream替换了iostream.h,看看会发生什么。我在代码中包含::ostream的地方遇到了一些编译器错误,所以将其更改为std::osttream解决了这个问题。接下来,我遇到了一个过载<lt;运算符,其中的所有位都使用std::iostream,但似乎<lt;命令尝试使用ostream(或basic_stream)。

我错过了什么?我想我必须更改更多导入旧io类的头文件。

inline std::ostream& operator<<(std::ostream& os, const PrinterInfo& pi)
{
os << pi.Idx() << ": " << pi.Name() << ", "
<< PrinterInfo::MapPrinterType(pi.GetPrinterType()) << ", "
<< PrinterInfo::MapPaperType(pi.GetPaperType()) << ", "
<< PrinterInfo::MapPrintFormat(pi.GetPrintFormat()) << ", "
<< PrinterInfo::MapRasType(pi.GetRasType()) << ", "
<< PrinterInfo::MapNPS(pi.NPS()) << ", "
<< "dpx = " << pi.Duplex() << ", "
<< "tray = " << pi.Tray2() << ", "
<< "port = " << pi.PortNo();
return os;
}

PrinterInfo类具有<lt;操作员:

inline std::ostream& operator<<(std::ostream& os, const PrinterOption& po)
{
os << "(" << po.Installed() << ", " << po.Enabled() << ")";
return os;
}

我不知道是不是这样,但如果你在类头文件中实现函数体,删除inline关键字,我也遇到了类似的问题,我浪费了2-3整天的时间和大量的重新编码来实现这一点。。。