[gameprogrammer] Re: How to assign a numeric variable to an std::string?
- From: Josh Stewart <aek@xxxxxxxxx>
- To: gameprogrammer@xxxxxxxxxxxxx
- Date: Wed, 16 Jan 2008 01:02:03 +0900
Does this work when running in locales that use a comma as the decimal
separator instead of a period?
-Josh
Kevin Jenkins wrote:
I ended up doing this, which is more flexible:
std::string query;
query+=FormatString("%i", 5);
// FormatString.cpp
#include "FormatString.h"
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#if defined(__GNUC__)
#define _vsnprintf vsnprintf
#endif
char * FormatString(const char *format, ...)
{
static int textIndex=0;
static char text[4][8096];
va_list ap;
va_start(ap, format);
if (++textIndex==4)
textIndex=0;
_vsnprintf(text[textIndex], 8096, format, ap);
va_end(ap);
text[textIndex][8096-1]=0;
return text[textIndex];
}
---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html
- References:
Other related posts:
- » [gameprogrammer] How to assign a numeric variable to an std::string?
- » [gameprogrammer] Re: How to assign a numeric variable to an std::string?
- » [gameprogrammer] Re: How to assign a numeric variable to an std::string?
- » [gameprogrammer] Re: How to assign a numeric variable to an std::string?
- » [gameprogrammer] Re: How to assign a numeric variable to an std::string?
- » [gameprogrammer] Re: How to assign a numeric variable to an std::string?
- » [gameprogrammer] Re: How to assign a numeric variable to an std::string?
- » [gameprogrammer] Re: How to assign a numeric variable to an std::string?
I ended up doing this, which is more flexible:
std::string query;
query+=FormatString("%i", 5);
// FormatString.cpp
#include "FormatString.h"
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#if defined(__GNUC__)
#define _vsnprintf vsnprintf
#endif
char * FormatString(const char *format, ...)
{
static int textIndex=0;
static char text[4][8096];
va_list ap;
va_start(ap, format);
if (++textIndex==4)
textIndex=0;
_vsnprintf(text[textIndex], 8096, format, ap);
va_end(ap);
text[textIndex][8096-1]=0;
return text[textIndex];
}