C++之__LINE__, __FILE__, __FUNCDNAME__宏定义

直接上结果
C++之__LINE__, __FILE__, __FUNCDNAME__宏定义_第1张图片

代码如下
#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();
}

你可能感兴趣的:(C++)