#ifndef INCLUDED_TTEMPSTR #define INCLUDED_TTEMPSTR //----------------------------------------------------------------------------- // // GarageGames.com // // Usage Examples: // // FILE *handle = fopen( TTempStr<256>("%s:\\%s\\%s.%s", drive, path, file, extension). "r" ); // // TTempStr<48> text; // strcpy(text, "this is a "); // strcat(text, "test"); // // TTempStr<24> buffer("hello %s", "world"); // puts(buffer); // buffer.set("who is number %d?", 2); // puts(buffer); // // puts( buffer.set("that's %s folks!", "all") ); // //----------------------------------------------------------------------------- #include #include #include template struct TTempStr { private: char mBuffer[Size]; public: TTempStr() { mBuffer[0] = '\0'; } TTempStr(const char *format, ...) { // Assert that the format string is not the internal buffer assert(format != mBuffer); va_list argList; va_start(argList, format); int length = vsprintf(mBuffer, format, argList); // Assert that there was no buffer overflow assert(length