Pretty-print C++ STL containers

前端 未结 10 1755
谎友^
谎友^ 2020-11-21 07:39

Please take note of the updates at the end of this post.

Update: I have created a public project on GitHub for this library!


10条回答
  •  醉酒成梦
    2020-11-21 07:47

    You can format containers as well as ranges and tuples using the {fmt} library. For example:

    #include 
    #include 
    
    int main() {
      auto v = std::vector{1, 2, 3};
      fmt::print("{}", v);
    }
    

    prints

    {1, 2, 3}
    

    to stdout.

    Disclaimer: I'm the author of {fmt}.

提交回复
热议问题