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

[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();
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值