I have a macro that I use a lot, inspired by another question:
#define to_string(x) dynamic_cast<ostringstream &> (( ostringstream() << setprecision(4) << dec << x )).str()
This is very convenient, for example, when using functions that accept string inputs:
some_function(to_string("The int is " << my_int));
However, I was told that using macros in C ++ is a bad practice, and in fact I had problems getting them to work on different compilers above. Is there a way to write this as another construct, for example. function, where will it have the same versatility?
source share