I have not used many variable parameters in the past, but recently I found it brings a lot of convenience ....
Below is an example of C LanguageCode:
# Include <stdio. h> # Include <Stdarg. h> Int Print ( Char * FMT ,...){ Char Buffer [ 1024 ] = { 0 }; Va_list Va; va_start (va, FMT); vsnprintf (buffer, sizeof (buffer), FMT, VA); va_end (VA ); Return Printf (buffer );} Int Main ( Int Argc, Char ** Argv) {print ( " % S % d % C \ n " , " Girl does not cry " , 100 , 65 ); Return 0 ;}
Note that the variable parameter function is in the C language, so if you use it in C ++, You need to define the function as follows:
Int _ cdeclPrint (Char*FMT ,...)
This is also useful in Windows programming. For example, when an error is displayed:
My previous practices are as follows:
CharBuf [128] = {0}; Wsprintf (BUF,"Error: % 08x", Getlasterror (); MessageBox (null, Buf, null, mb_ OK| Mb_iconexclamation );
Now, you don't need to define the variables. You can simply do it in one sentence:
Msgbox (null, null, mb_ OK | mb_iconexclamation, "% S % d % C", "girl does not cry", 100, 'A ');
Girl don't cry (QQ: 191035066) @ 2012-05-10 22:41:13 @ http://www.cnblogs.com/nbsofer