How to read entire stream into a std::string?

后端 未结 7 995
灰色年华
灰色年华 2020-11-29 19:15

I\'m trying to read an entire stream (multiple lines) into a string.

I\'m using this code, and it works, but it\'s offending my sense of style... Surely there\'s an

7条回答
  •  心在旅途
    2020-11-29 19:25

    Perhaps this 1 line C++11 solution:

    std::vector s{std::istreambuf_iterator{in},{}};
    

提交回复
热议问题