C++ format macro / inline ostringstream

前端 未结 7 1361
不知归路
不知归路 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 03:36

    When I took mrree's solution (the one marked "preferred", the one beautifully explained, and the one working perfectly for G++), I ran into problems with MSVC++: All strings built with this macro ended up empty.

    Hours (and lots of scratching my head and asking a "reloaded" question here) later, I found out that the seekp() call was the culprit. I am not sure what MSVC++ does differently with that, but replacing

    ostringstream().seekp( 0, ios_base::cur )
    

    with cadabra's

    ostringstream() << std::dec
    

    works for MSVC++, too.

提交回复
热议问题