How in c++ create message similar to snprintf and just change value in message? -
how can create message similar snprintf ( can have generic text %d integer , when need show in sprintf connect parameter), avoid concatenation? (i need create result string you need more %d coins
, @ moment doing on bad way concatenate , return value 'you need more' + some_stringified_value + 'coins'
)
the "canonical" c++ way use stringstream
, this:
std::string somefunc(int number) { std::stringstream ss; ss << "you need " << number << " more coins"; std::string str = ss.str(); return str; }
Comments
Post a Comment