Skip to main content
gamedev.net
🔒 Locked

Wrapper for wsprintf function

Started by Ace17 1 reply 850+ views
Original Post
Ace17
Ace17
I''m planning to write a logger class I need a function like this : void Output(char* s, ...) { char buffer[256]; wsprintf(buffer, s, ...); fwrite(buffer, 1, strlen(buffer), file); } Use like this : Output("value = %d ", value); Output("%d %d %d", int(1), int(2), int(3)); The syntax isn''t correct, of course. So if somebody knows the right syntax... Thanx
http://acecorp.free.fr
VolkerG
VolkerG
look for wvsprintf and va_arg, va_end and va_start in the MSDN.
Here is an example how to handle the variable argument;
  
void _Trace (LPCTSTR lpszFormat, ...)
{
va_list argList;
TCHAR szStrBuffer[1024];

va_start (argList, lpszFormat);
_vsntprintf (szStrBuffer, sizeof (szStrBuffer) / sizeof (szStrBuffer[0]), lpszFormat,
argList);
OutputDebugString (szStrBuffer);
OutputDebugString (_T("\n"));
va_end (argList);
}


Edited by - VolkerG on October 20, 2001 2:04:45 PM
Gorg
Gorg
If you are using C++, you should know that the STL has something call a string stream that can do this very nicely.




#include


...

std::ostringstream os;

int j = 3;

float v = 2;


os << "my int value is : " << j
<< ". My float value is : " << v;

std::string theStringFromTheOs = os.str();

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.