need C++ help (for code that will become part of GME)

Jonathan Sprinkle sprinkle at eecs.berkeley.edu
Wed Nov 19 12:52:15 CST 2003



----------
From: 	Jonathan S.
Sent: 	Wednesday, November 19, 2003 2:52:15 PM
To: 	GME Group
Subject: 	RE: need C++ help (for code that will become part of GME)
Auto forwarded by a Rule

Whooooa, stallion.  Here's the code snippet, but you should be wanred that in general, passing a variable number of arguments is hackworthy, especially when theya re void's.
 
The trick is to use "v{f,s, }printf" instead of {f,s, }printf, and pass the poitner to the arglist (v1 below). You can tell taht someone has wanted to do this before.  :)
 
good luck,
Jon
 
#include <cstdio>
#include <iostream>
#include <string>
#include <stdarg.h>
using namespace std;
 
string MyPrintf( char * sz, ... );
 
void main( void )
{
 cout << MyPrintf( "My name is %s %s %s", "Jonathan", "Mark", "Sprinkle" ) << endl;
}
 
string MyPrintf( char * sz, ... )
{
 string result;
 char jon[2222]="";
 
 va_list v1;
 va_start( v1, sz );
 vsprintf( jon, sz, v1 );
 va_end( v1 );
 result = string( jon );
 return result;
}



More information about the gme-users mailing list