64,642
社区成员
发帖
与我相关
我的任务
分享
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;
}
------
00401000
#include <Windows.h>
#include <iostream>
#include <sstream>
using namespace std;
template<class _Elem,
class _Traits> inline
basic_ostream<_Elem, _Traits>&
__CLRCALL_OR_CDECL endd(basic_ostream<_Elem, _Traits>& _Ostr)
{ // insert newline and flush stream
ostringstream& oo = (ostringstream&)_Ostr;
OutputDebugStringA(oo.str().c_str());
oo.str("");
return (_Ostr);
}
int _tmain(int argc, _TCHAR* argv[])
{
ostringstream dout;
dout<<"this is "<<endd;
cout<<"ok"<<endl;
return 0;
}
#include <iostream>
#include <sstream>
#include <string>
namespace std
{
class dbgout : public ostringstream
{
public:
dbgout& __CLR_OR_THIS_CALL operator<<(dbgout& (__cdecl *_Pfn)(dbgout&))
{
cout << "test" << endl; // 根本没进来啊
_DEBUG_POINTER(_Pfn);
return ((*_Pfn)(*this));
}
protected:
private:
};
dbgout& __cdecl endd(dbgout& _Ostr)
{
cout << "test" << _Ostr.str() << endl;
OutputDebugStringA(_Ostr.str().c_str());
return _Ostr;
}
}
using namespace std;
int main()
{
dbgout dd;
dd << "------" << endl << endd;
cout << dd.str();
return 0;
}