#ifndef LOGHELPER_H
#define LOGHELPER_H
#include
#include
struct debug
{
debug()
{
}
~debug()
{
std::cerr << m_SS.str() << std::endl;
}
public:
// accepts just about anything
template
debug &operator<<(const T &x)
{
m_SS << x;
return *this;
}
private:
std::ostringstream m_SS;
};
#define LOG_INFO debug()
#define LOG_ERROR debug()
#endif // LOGHELPER_H
借鉴来自网络,
使用方法:
#include "LogHelper.h"
LOG_INFO << "hello loginfo";
等价于std::cout << "hello loginfo" <