[color=red][size=x-large]直接上结果[/size][/color]
[img]http://dl2.iteye.com/upload/attachment/0092/4695/33226b05-0f4c-357c-b4ad-e4296881ec72.png[/img]
[color=red][size=x-large]代码如下[/size][/color]
[img]http://dl2.iteye.com/upload/attachment/0092/4695/33226b05-0f4c-357c-b4ad-e4296881ec72.png[/img]
[color=red][size=x-large]代码如下[/size][/color]
#include <iostream>
#include <typeinfo>
#include <iomanip>
/*
@file 学习__LINE__, __FILE__, __FUNCDNAME__ 等宏定义的用法
@link http://msdn.microsoft.com/zh-cn/library/b0084kay.aspx
@link http://www.cnitblog.com/zouzheng/archive/2007/08/31/32691.aspx
*/
#pragma region 测试 函数名的三个宏,不是ANSI的标准宏
void testFunctionMacro (int a, float b) {
std::cout << std::endl;
std::cout << std::left << std::setw(16) << "__FUNCTION__" << " : " << __FUNCTION__ << std::endl;
std::cout << std::left << std::setw(16) << "__FUNCDNAME__" << " : " << __FUNCDNAME__ << std::endl;
std::cout << std::left << std::setw(16) << "__FUNCSIG__" << " : " << __FUNCSIG__ << std::endl;
}
void testFunctionMacro (int a) {
std::cout << std::endl;
std::cout << std::left << std::setw(16) << "__FUNCTION__" << " : " << __FUNCTION__ << std::endl;
std::cout << std::left << std::setw(16) << "__FUNCDNAME__" << " : " << __FUNCDNAME__ << std::endl;
std::cout << std::left << std::setw(16) << "__FUNCSIG__" << " : " << __FUNCSIG__ << std::endl;
}
// Demonstrates functionality of __FUNCTION__, __FUNCDNAME__, and __FUNCSIG__ macros
void testFunctionMacro() {
std::cout << std::endl;
std::cout << std::left << std::setw(16) << "__FUNCTION__" << " : " << __FUNCTION__ << std::endl;
std::cout << std::left << std::setw(16) << "__FUNCDNAME__" << " : " << __FUNCDNAME__ << std::endl;
std::cout << std::left << std::setw(16) << "__FUNCSIG__" << " : " << __FUNCSIG__ << std::endl;
}
#pragma endregion
#pragma region 测试__LINE__等宏,ANSI的标准宏
void test__ANSI__Macro() {
std::cout << std::left << std::setw(16) << "__FILE__" << " : " << __FILE__ << std::endl;
std::cout << std::left << std::setw(16) << "__LINE__" << " : " << __LINE__ << std::endl;
std::cout << std::left << std::setw(16) << "__DATE__" << " : " << __DATE__ << std::endl;
std::cout << std::left << std::setw(16) << "__TIME__" << " : " << __TIME__ << std::endl;
std::cout << std::left << std::setw(16) << "__TIMESTAMP__" << " : " << __TIMESTAMP__ << std::endl;
}
#pragma endregion
void main() {
test__ANSI__Macro();
std::cout << std::endl;
testFunctionMacro (1, 2);
testFunctionMacro (1);
testFunctionMacro();
}