首页 > 其他 > 详细

日志 位置宏。。。

时间:2014-01-21 21:16:38      阅读:345      评论:0      收藏:0      [点我收藏+]

//利用预编译宏展开特性
#define  LOCATION Location(__FILE__, __FUNCTION__, __LINE__)

inline std::string Location(char *pfile, char *pfunc, int nline)
{
    char buffer[MAX_PATH];// MAX_PATH = 260
    sprintf_s(buffer, "%s %s %d", pfile, pfunc, nline);

    return buffer;
}

 

测试了,可行,但,还是用的宏,唔。。。

改成这样吧:

 

#define LOCATION Location(__FILE__, __FUNCTION__, __LINE__)

inline std::string Location(const string &pfile
, const string &pfunc, int nline)
{
// char buffer[MAX_PATH];// MAX_PATH = 260
// sprintf_s(buffer, "%s %s %d", pfile, pfunc, nline);

ostringstream sst;
sst << pfile << "\t"<< pfunc<< "\t" << nline;

return sst.str();
}

 

嘿嘿,再改一次:

 

inline std::string Location(const string &pfile
, const string &pfunc, int nline)
{
// char buffer[MAX_PATH];// MAX_PATH = 260
// sprintf_s(buffer, "%s %s %d", pfile, pfunc, nline);

static ostringstream sst;
sst.str("");

sst << pfile << "\t"<< pfunc<< "\t" << nline;

return sst.str();
}

日志 位置宏。。。

原文:http://www.cnblogs.com/xiarl/p/3528510.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!