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

Willink, Ed Ed.Willink at thalesgroup.com
Thu Nov 20 07:57:59 CST 2003



----------
From: 	Ed Willink
Sent: 	Thursday, November 20, 2003 1:57:59 AM
To: 	GME Group
Subject: 	RE: need C++ help (for code that will become part of GME)
Auto forwarded by a Rule

Hi

If you want to make it as smart as printf; in C++ you'll use operator<<().

Regards

Ed Willink

------------------------------------------------------------------------

E.D.Willink, Email: mailto:EdWillink at iee.org

Thales Research and Technology (UK) Ltd, Tel: +44 118 923 8278 (direct)

Worton Drive, or +44 118 986 8601 (ext 8278)

Worton Grange Business Park, Fax: +44 118 923 8399

Reading, RG2 0SB

ENGLAND http://www.computing.surrey.ac.uk/personal/pg/E.Willink

------------------------------------------------------------------------

-----Original Message-----
From: GME Group [mailto:gmegroup at isis.vanderbilt.edu]
Sent: 19 November 2003 21:00
To: GME List
Subject: FW: need C++ help (for code that will become part of GME)





----------

From:   Brian Williams 
Sent:     Wednesday, November 19, 2003 2:59:57 PM 
To:      GME Group 
Subject:       RE: need C++ help (for code that will become part of GME) 
Auto forwarded by a Rule


Thanks Jon,

 

I shoulda made the subject say "code that _may_ become part of GME", because
of course, I have to make it work first.

 

I have already made a function that just takes strings, and dumps them to a
file (GME Event Logging), but I'd like to make it as smart as printf, so
instead adding several lines of code everywhere an interesting event occurs,
I can just add one.

 

Brian

 

-----Original Message-----
From: GME Group 
Sent: Wednesday, November 19, 2003 2:52 PM
To: GME List
Subject: FW: need C++ help (for code that will become part of GME)

 

 


----------

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