C++之__LINE__, __FILE__, __FUNCDNAME__巨集定義
阿新 • • 發佈:2019-01-10
[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();
}