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

后端 未结 7 998
灰色年华
灰色年华 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:20

    Well, if you are looking for a simple and 'readable' way to do it. I would recomend add/use some high level framework on your project. For that I's always use Poco and Boost on all my projects. In this case, with Poco:

        string text;
        FileStream fstream(TEXT_FILE_PATH);
        StreamCopier::copyToString(fstream, text);
    

提交回复
热议问题