__FUNCTION__返回函数名的宏定义

Posted on 2020-04-28 10:51  yacbo  阅读(701)  评论(0编辑  收藏  举报

   从当前运行的函数中得到函数名,使用__FUNCTION__ 及相关宏。

举例如下

#include <iostream>
#include <string>
using namespace std;
const char* hello()
{
    return __FUNCTION__;//返回函数名
}
const char*world()
{
    return __FUNCTION__;
}
int main()
{
    cout << hello() << endl << world() << endl;
    system("pause");
    return 0;
}

 

Copyright © 2024 yacbo
Powered by .NET 8.0 on Kubernetes