C++ format macro / inline ostringstream
问题 I'm trying to write a macro that would allow me to do something like: FORMAT(a << "b" << c << d) , and the result would be a string -- the same as creating an ostringstream, inserting a...d , and returning .str() . Something like: string f(){ ostringstream o; o << a << "b" << c << d; return o.str() } Essentially, FORMAT(a << "b" << c << d) == f() . First, I tried: 1: #define FORMAT(items) \ ((std::ostringstream&)(std::ostringstream() << items)).str() If the very first item is a C string (