Home Forum RSS PGP Alerts Links (D) |
|
Remembering C++ stream operators Comment on this articleGetting the syntax right when overloading stream operators isn't easy. If you take the simplest way, you'll soon discover the operator isn't found for streams like wstringstream. Actually, the most common stream operator prototypes don't catch 16-bit character streams. The right stuff I found in Josuttis book, and it looks like: template <class charT, class traits> inline std::basic_ostream<charT,traits>& operator<<(std::basic_ostream<charT,traits>& strm, const QDate& qd) { wstring wstrDate; qd.date2String(&wstrDate); strm << wstrDate.c_str(); return strm; } I've greyed out the stuff that isn't universal in the example above. Have fun! |
TOP |