C++庫或軟件版本宏定義方式示例

#include <iostream>
#include <string>

#define XX_VERSION_MAJOR        1        // 主版本號
#define XX_VERSION_MINOR        1        // 副版本號    
#define XX_VERSION_REVISION     1        // 修正版本號
#define XX_VERSION_STATUS       "Alpha"

#define XX_AUX_STR_EXP(__A)     #__A
#define XX_AUX_STR(__A)         XX_AUX_STR_EXP(__A)

// 寬字符表示
#define XX_AUX_WSTR_EXP(__A)    L ## #__A
#define XX_AUX_WSTR(__A)        XX_AUX_WSTR_EXP(__A)

#define XX_VERSION_STR          XX_AUX_STR(XX_VERSION_MAJOR) "."     \
                                XX_AUX_STR(XX_VERSION_MINOR) "."     \
                                XX_AUX_STR(XX_VERSION_REVISION) " "  \
                                XX_VERSION_STATUS
                                
#define XX_VERSION_WSTR         XX_AUX_WSTR(XX_VERSION_MAJOR) "."    \
                                XX_AUX_WSTR(XX_VERSION_MINOR) "."    \
                                XX_AUX_WSTR(XX_VERSION_REVISION) " " \
                                XX_VERSION_STATUS

int main(int argc, char *argv[])
{
    std::cout << XX_VERSION_STR << std::endl;
    std::wcout << XX_VERSION_WSTR << std::endl;
    
    std::string str = XX_VERSION_STR;
    std::wstring wstr = XX_VERSION_WSTR;
    std::cout << str << std::endl;
    std::wcout << wstr << std::endl;
    
    return 0;
}

 

編譯器: gcc 7.4.0

結果:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章