std::string equivalent for data with null characters?

前端 未结 5 1160
梦谈多话
梦谈多话 2021-01-13 18:57

I\'d like to read a binary file and use something like std::string that automatically resizes the buffer and such.

I\'m using Visual C++. What are my op

5条回答
  •  死守一世寂寞
    2021-01-13 19:40

    std::string allows NUL characters so you can just go ahead and use that.

    There is no problem with using c_str() or data(). Yes, the embedded NULs will be in your data, but if you don't use them to terminate your strings (you'll need to call length() to find out how many bytes are in your string) then all will be good.

提交回复
热议问题