2014年3月22日16:59:19
__FILE__和__FUNCTION__的使用
1、使用VS2008创建一个带预编译头的控制台项目。
2、源文件内容:
#include "stdafx.h"
#include<iostream>
using namespace std;
class CEntry
{
int m_a;
public:
void test()
{
char strLog[400]={0};
sprintf(strLog,"文件 函数 :%s,%s",__FILE__,__FUNCTION__);
printf("%s",strLog);
}
};
int main( void )
{
CEntry aEntry;
aEntry.test();
char ch;
cin>>ch;
return 0;
}
本文通过一个简单的C++示例介绍了如何在代码中使用预处理器宏__FILE__和__FUNCTION__来获取当前文件名和函数名。此技巧对于调试和日志记录非常有用。
1147

被折叠的 条评论
为什么被折叠?



