View previous topic :: View next topic |
Author |
Message |
rapion124 Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Mar 2007 Posts: 1095
|
Posted: Tue Apr 29, 2008 6:28 pm Post subject: [C++] va_list |
|
|
I just started C++ a few months ago. One concept I still don't understand is a function that takes an infinite number of arguments i.e. printf(). Then, I saw that it has something to do with va_list and va_arg. Can anyone explain to me how to use them?
|
|
Back to top |
|
 |
Renkokuken GO Moderator
Reputation: 4
Joined: 22 Oct 2006 Posts: 3249
|
|
Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Wed Apr 30, 2008 10:32 am Post subject: |
|
|
Example:
Code: | void __cdecl DebugPrintF(const TCHAR *format, ...)
{
TCHAR buf[4096], *p = buf;
va_list args;
va_start(args, format);
p += _vsntprintf_s(p, sizeof buf, sizeof buf-1, format, args);
va_end(args);
while ( p > buf && isspace(p[-1]) )
*--p = '\0';
*p++ = '\r';
*p++ = '\n';
*p = '\0';
OutputDebugString(buf);
} |
_________________
- Retired. |
|
Back to top |
|
 |
|