class dbgout:public ostringstream
{
public:
dbgout& __CLR_OR_THIS_CALL operator<< (dbgout& (__cdecl *_Pfn)(dbgout&))
{
_DEBUG_POINTER(_Pfn);
return ((*_Pfn)(*this));
}
protected:
private:
};
namespace std{
dbgout& __cdecl endd(dbgout& _Ostr)
{
OutputDebugStringA(_Ostr.str().c_str());
return _Ostr;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
dbgout dd;
dd<<"------"<<endl<<endd;
cout<<dd.str();
return 0;
}
如上,意思很明确,想做一个函数endd,调用使OuputDebugString输出。编译成功,运行结果:
------
00401000
情况:一:多余输出了endd函数的地址。二:并没有调用OuputDebugString。
那么,应该怎么写。请赐教,谢谢!