operator<<
如果我的对象需要打印 astd::wstring
以及 ints 等,我该如何编写输出?
#include <iostream>
struct Foo {
int i;
std::wstring wstr;
};
std::ostream& operator<<(std::ostream& out, Foo const& foo) {
out << foo.i << foo.wstr; // error
return out;
}
int main() {
Foo foo;
std::wcerr << foo << std::endl;
}
换句话说:int
如果我通过 a ,我如何打印 s 和其他原始数据类型wcerr
?我需要boost::lexical_cast<std::wstring>
或类似的吗?