vector vs string for binary data

后端 未结 9 2179
日久生厌
日久生厌 2020-12-05 07:25

Which is a better c++ container for holding and accessing binary data?

std::vector

or

std::string
         


        
9条回答
  •  醉酒成梦
    2020-12-05 07:38

    Personally I prefer std::string because string::data() is much more intuitive for me when I want my binary buffer back in C-compatible form. I know that vector elements are guaranteed to be stored contiguously exercising this in code feels a little bit unsettling.

    This is a style decision that individual developer or a team should make for themselves.

提交回复
热议问题