64,648
社区成员
发帖
与我相关
我的任务
分享
LOG<<"123"<<456; //成功
LOG<<std::endl;//报错
#pragma once
#include <Windows.h>
#include <string>
#include <iostream>
class CLog
{
private:
CRITICAL_SECTION m_cs;
public:
CLog()
{
InitializeCriticalSection(&m_cs);
}
~CLog()
{
DeleteCriticalSection(&m_cs);
}
template<class T>
CLog& operator<<(T t)
{
EnterCriticalSection(&m_cs);
std::cout << t;
LeaveCriticalSection(&m_cs);
return *this;
}
};
CLog g_log;
#define LOG g_log
CLog& operator << (std::ostream& (*pfn) (std::ostream&))
{
std::cout << "here";
std::cout << pfn;
return *this;
}
_CRTIMP2_PURE inline basic_ostream<char, char_traits<char> >&
__CLRCALL_OR_CDECL endl(basic_ostream<char, char_traits<char> >& _Ostr)
{ // insert newline and flush byte stream
_Ostr.put('\n');
_Ostr.flush();
return (_Ostr);
}
_Myt& __CLR_OR_THIS_CALL operator<<(_Myt& (__cdecl *_Pfn)(_Myt&))
{ // call basic_ostream manipulator
_DEBUG_POINTER(_Pfn);
return ((*_Pfn)(*this));
}