我在joelonsoftware.com http://discuss.joelonsoftware.com/default.asp?joel.3.594503.11的存档文件中发现了这个问题  “嗨,    我今天过得特别慢,  令我无法理解操作员  超载问题。我想要一个  类,以便能够通过  插入运算符,即:    myClassInstance   字符串“)    在内部,我希望一切都结束  在字符串流中,这样我就可以  耕种到其他溪流(例如  std :: cout和ofstream)。我有  我非常困惑我该怎么做  无需编写运算符  每种数据类型的重载,以及如何  输入流将在  第一次调用(myClassInstance   ...)。    非常感谢您的帮助!”这正是我想要做的。我找到了通过定义模板来处理所有类型的方法,以及通过另一种重载方法来处理类似ostream类中定义的endl的操纵器的方法。UIStream& UIStream ::operator << (const T str) { CString cstr(stringify(str).c_str()); theFrame->m_pOutputView->WriteMessage(cstr); return *this; } //for manipulators like std::endlUIStream& UIStream ::operator <<(ostream& (*m)(ostream&)){ //stream<<*m; //CString cstr((*m)(new ostream).c_str()); if(*m==&std::endl); theFrame->m_pOutputView->WriteMessage("\n"); return (*this);}我仍在与采用十六进制dec或oct这样的参数的操纵器作斗争,这些参数在ios_base中定义。 (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 可能是读一本关于该主题的好书的想法。我推荐Langer和Kreft的Standard C++ IOStreams and Locales。 (adsbygoogle = window.adsbygoogle || []).push({});
10-04 20:58