Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Wrapper for wsprintf function

This topic is 6178 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post

Link to post
Share on other sites
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,
OutputDebugString (szStrBuffer);
OutputDebugString (_T("\n"));
va_end (argList);

Edited by - VolkerG on October 20, 2001 2:04:45 PM

Share this post

Link to post
Share on other sites
If you are using C++, you should know that the STL has something call a string stream that can do this very nicely.



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();

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!