概述
[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();
}
最后
以上就是笑点低裙子为你收集整理的C++之__LINE__, __FILE__, __FUNCDNAME__宏定义的全部内容,希望文章能够帮你解决C++之__LINE__, __FILE__, __FUNCDNAME__宏定义所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复