If we reinvent std::string, you can get half way there :P
Or, you could just ignore the extra copy and just use std::string.
Here's a c++11 templated version I'm using.
template<class... Args >
std::string makeString(const char* format, Args&&... args) {
char buffer[256];
int len = snprintf(buffer, 256, format, std::forward<Args>(args)...);
if(len >= 256) {
// if string is too long, try again with a bigger buffer
char buffer[len + 1];
snprintf(buffer, len + 1, format, std::forward<Args>(args)...);
return buffer;
}
return buffer;
}
.
Edit: Hmm. Maybe I should read the topic more carefully before answering. Oh well, I'll leave this here anyway. Back to work and getting stuff compiling I guess...