#define TRACK(s) ("File: " __FILE__  " : " s )        //
调用是用 FUNC1(TRACK("This is test message "))        //这宏没问题,可以正常调用但是我如何如下写这个宏,就不行了.
#define TRACK(s) ("File: " __FILE__ " Line: "  __LINE__ " : " s )我想把当前程序文件名和当前的行号及参数s 联结成一字符串, 以宏的方式达到这个功能 该如何写?两天了,都没找到结果.所以在此发贴求助.
谢谢

解决方案 »

  1.   

    __LINE__是一个无符号数,不是字符串
      

  2.   

    __LINE__是一个无符号数,表示行号
      

  3.   

    使用一个不常用的技巧(在boost里面出现过)可以达到一般的效果:
    #define PRE(l) #l
    #define DOPRE(l) PRE(l)
    #define   TRACK(s)   ( "File:   "   __FILE__   "   Line:   "    DOPRE(__LINE__)   "   :   "   s   ) 输出:
    File:   e:\111\111.cpp   Line:   (__LINE__Var+1)   :   in fun first line
    File:   e:\111\111.cpp   Line:   (__LINE__Var+3)   :   in main third line
    Press any key to continue
      

  4.   

    #define   TRACK(_S_)\
    {\
    CHAR szBuf[1024];\
    sprintf(szBuf, "File: %s Line: %d  Mesage: %s", __FILE__, __LINE__, _S_);\
    TRACE(szBuf);\
    }\TRACK(  "This   is   test   message   "  );
      

  5.   

    呵呵,解决了,贴出来// __FILE__, __LINE__是ANSI C标准,__FUNCTION__是VC扩展,在vc.net中才有
    #ifndef __FUNCTION__
    #define __FUNCTION__ NULL
    #endif // __FUNCTION__const static int LINE_BUFFER_SIZE = 1024;
    #define TRACK(msg)  BindLogInfo(__FILE__, __LINE__, __FUNCTION__, msg)LPTSTR BindLogInfo(const char* file, int line, const char* func, const char * msg)
    {
    TCHAR * strInfo;
    strInfo = (TCHAR *)malloc(sizeof(TCHAR) * LINE_BUFFER_SIZE);
    if (NULL == strInfo) return NULL;
    memset(strInfo, 0, sizeof(TCHAR) * LINE_BUFFER_SIZE);
    _stprintf(strInfo,_T("File: %s Line: %d function: %s Info: %s"), file,line, func, msg);
    return strInfo;
    }TRACK("this is test message! \r\n")