http://GameProgrammer.Com

Programming

GP Mailing List
     Thread Index
     Date Index

ATXGPSIG List
     Thread Index
     Date Index

Google
>

Home

Wise2Food



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gameprogrammer] Re: How to assign a numeric variable to an std::string?



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