日志 位置宏。。。
//利用预编译宏展开特性
#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();
}