What is the best way (short, using standard libraries and easy to understand) to do this in c++:
std::string s = magic_command("%4.2f", 123.456f)
- without length limitations (char s[1000] = ...)
- where "%4.2f" is any c format string (which would be given to printf for example)
I am aware of the snprintf malloc combo suggested for pure c in
writing formatted data of unknown length to a string (C programming)
but is there a better, less verbose, way to do this with c++?
I am also aware of the std::ostringstream method suggested in
Convert float to std::string in C++
but I want to pass a c format string such as "%4.2f", and I could not find a way to do this with ostringstream.