James OMeara writes:
It appears you are correct. I could have sworn I found an article about this
somewhere (new overloaded function?), but I can’t for the life of me refind
it. My apologies for the confusion.
No problem, I sat something about a stream or something, and I’ll see if I can
build upon that. Your c_str() part really helped, though
I find building strings from char[]s, ints, FooBars, etc. so common I
wrote this:
//
// -------------------------------------------------------------------
// STR
//
// Macro STR(x << y << z) builds a string by concatenating x, y, z.
// -------------------------------------------------------------------
//
#include
#include
class Str {
public:
Str() {}
template
Str &operator <<(const T &t) {
stream_ << t;
return *this;
}
std::string &str() {
string_ = stream_.rdbuf()->str();
return string_;
}
operator std::string &() {
return str();
}
operator const char *() {
return str().c_str();
}
private:
std::ostringstream stream_;
std::string string_;
};
#define STR(expr) ((Str() << expr).str())
//
// -------------------------------------------------------------------
//
Now you can do:
sur = TTF_RenderText_Solid(font, STR(100), fg);
or:
sur = TTF_RenderText_Solid(font, STR("Level " << level), fg);
or:
sur = TTF_RenderText_Solid(font, STR(minutes << “:” << seconds << “.” << hundredths), fg);
etc.
HTH