可变参数个数。
printf(char* fmt, ...)

解决方案 »

  1.   

    表示可以有可变数量的参数,你常用的printf就是这样定义的
      

  2.   

    这表示这个函数可以接收不定个数的参数,但不能少于...前面已经定义的参数。printf()就是这种函数的一个典型。
      

  3.   

    呵,就好比int sprintf( char *buffer, const char *format [, argument] ... );这个函数,MSDN里面讲得好清楚:是指明函数可以接受多于函数定义的参数~~~~以下是MSDN的说明:Ellipses and Default Arguments
    Functions can be declared to accept fewer arguments than specified in the function definition, using one of two methods: ellipsis (...) or default arguments.Ellipses denote that arguments may be required but that the number and types are not specified in the declaration. This is normally poor C++ programming practice because it defeats one of the benefits of C++: type safety. Different conversions are applied to functions declared with ellipses than to those functions for which the formal and actual argument types are known: If the actual argument is of type float, it is promoted to type double prior to the function call.
    Any signed or unsigned char, short, enumerated type, or bit field is converted to either a signed or an unsigned int using integral promotion.
    Any argument of class type is passed by value as a data structure; the copy is created by binary copying instead of by invoking the class’s copy constructor (if one exists). 
    Ellipses, if used, must be declared last in the argument list. For more information about passing a variable number of arguments, see the discussion ofva_arg, va_start, and va_list in the Run-Time Library Reference. Default arguments enable you to specify the value an argument should assume if none is supplied in the function call. The following code fragment shows how default arguments work. For more information about restrictions on specifying default arguments, see Default Arguments. #include <iostream.h>// Declare the function print that prints a string,
    // then a terminator.
    void print( const char *string,
                const char *terminator = "\n" );void main()
    {
        print( "hello," );
        print( "world!" );    print( "good morning", ", " );
        print( "sunshine." );
    }// Define print.
    void print( char *string, char *terminator )
    {
        if( string != NULL )
            cout << string;    if( terminator != NULL )
            cout << terminator;
    }The preceding program declares a function, print, that takes two arguments. However, the second argument, terminator, has a default value, "\n". In main, the first two calls to print allow the default second argument to supply a new line to terminate the printed string. The third call specifies an explicit value for the second argument. The output from the program ishello,
    world!
    good morning, sunshine.
    --------------------------------------------------------------------------------
    Send feedback to MSDN.Look here for MSDN Online resources.
      

  4.   

    实例如写日志文件实现:
    void WriteSysLog(LPCTSTR pszFormat, ...)
    void WriteSysLog(LPCTSTR pszFormat, ...)
    {
    HANDLE hFile ;
    DWORD dwByteWritten ;    _TCHAR buf[1024];
        wsprintf(buf, "(%lu): ", GetCurrentThreadId());
    va_list arglist;
    va_start(arglist, pszFormat);
        vsprintf(&buf[lstrlen(buf)], pszFormat, arglist);
    va_end(arglist); hFile = CreateFile(_TEXT("..\\LogData\\SysRunLog.log"),
    GENERIC_WRITE,
    FILE_SHARE_WRITE ,
    (LPSECURITY_ATTRIBUTES)NULL,
    OPEN_ALWAYS,
    FILE_ATTRIBUTE_NORMAL,
    (HANDLE)NULL) ;

    if (hFile == NULL) 
    return ; DWORD dwSize = GetFileSize (hFile, NULL) ;
    if(dwSize != 0xFFFFFFFF)
    {
    if( dwSize > 3000000)
    {
    SetFilePointer (hFile, 0, NULL, FILE_BEGIN) ; 
    SetEndOfFile (hFile) ;
    }

    } SetFilePointer (hFile, 0, NULL, FILE_END) ;  CString szTm ;
    CTime cTm = CTime::GetCurrentTime() ;
    szTm = cTm.Format ("%Y.%m.%d-%H:%M:%S ") ; WriteFile(hFile, szTm, _tcslen(szTm)*sizeof(_TCHAR), &dwByteWritten, NULL) ;
    WriteFile(hFile, buf, _tcslen(buf)*sizeof(_TCHAR), &dwByteWritten, NULL) ;
    WriteFile(hFile, _TEXT("\x0D\x0A"), 2*sizeof(_TCHAR), &dwByteWritten, NULL) ; CloseHandle (hFile) ;

    return  ;
    }
      

  5.   

    没办法,碰到问题为什么不先查查MSDN呢?唉。。
      

  6.   

    the answer above is enough