C++ format macro / inline ostringstream

前端 未结 7 1290
不知归路
不知归路 2020-12-01 03:18

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 s

相关标签:
7条回答
  • 2020-12-01 04:03

    Here's a working solution:

    #define FORMAT(items)                                                   \
       ((std::ostringstream&)(std::ostringstream() << std::dec << items)).str()
    

    I don't quite understand the behavior of the first argument.

    0 讨论(0)
提交回复
热议问题