我搜索了高和低,但还没有找到答案,所以请原谅,如果这是重复的。C++运算符<<调用:: ostream而不是std :: ostream
我有一些很旧的C++代码,我试图轻易地转换成这个千年。代码仍然在Visual Studio 6中编译,需要继续这样做,但我也试图让它在Visual Studio 2017中工作。我之前完成了这个工作,但对头文件等进行了很多更改,这次我是尝试更多的测量方法。
该代码已经使用了混合的stl和非stl,旧的和新的io头等,所以这是一个混乱等待爆炸。
作为一个简单的开始,我只是用iostream替换了iostream.h,看看会发生什么。我得到了一些编译器错误,其代码中有:: ostream,因此将其更改为std :: ostream可以解决该问题。接下来,我遇到一个运算符超载的问题,其中的所有位都使用std :: iostream,但似乎命令尝试使用ostream(或basic_ostream)。
我缺少什么?我想我必须更换一些更多的头文件来导入旧的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类有对< <运营商以及一个覆盖:
inline std::ostream& operator<<(std::ostream& os, const PrinterOption& po)
{
os << "(" << po.Installed() << ", " << po.Enabled() << ")";
return os;
}
是'PrinterOption'或'PrinterInfo'在一个单独的命名空间? – Slava
是的,这些代码大部分都是在90年代写的,所以在一般的命名空间中没有任何指定。 –
那么,这个代码有什么问题?你期望的结果是什么,你观察到了什么,以及这两者有什么不同?你会得到编译器错误,意外的输出,还有其他的东西? –