也就是参数个数不确定

解决方案 »

  1.   

    WriteLogFileForDllEx(char *szFmt, ...)
    {
    CString szFileName("");
    CString szFormat("");
    char szTemp[1024];
    va_list argptr; va_start(argptr, szFmt);
    vsprintf(szTemp, szFmt, argptr);
    va_end(argptr);

    szFileName.Format(_T("%s_%s"), SZ_MODULENAME, SZ_VERSION);
    szFormat.Format(_T("%s"), szTemp);

    }
      

  2.   

    void CMyDebug::AfxMyTrace(LPCTSTR lpszFormat, ...)
    {
             ..........
    va_list args;
    va_start(args, lpszFormat);

    int nBuf;
    TCHAR szBuffer[512];

    nBuf = _vsntprintf(szBuffer, sizeof(szBuffer)/sizeof(szBuffer[0]), lpszFormat, args);

    // was there an error? was the expanded string too long?
    ASSERT(nBuf >= 0);
    va_end(args);
             ..........

    }
      

  3.   

    int printf(
       const char *format [,
       argument]... 
    );
      

  4.   

    int average( int first, ... )
    {
       int count = 0, sum = 0, i = first;
       va_list er;   va_start( er, first );     /* Initialize variable arguments. */
       while( i != -1 )
       {
          sum += i;
          count++;
          i = va_arg( er, int);
       }
       va_end( er );              /* Reset variable arguments.      */
       return( sum ? (sum / count) : 0 );
    }
    MSDN上的例子,如果不使用-1作为结束参数,这个函数怎么写?