vector vs string for binary data

后端 未结 9 2195
日久生厌
日久生厌 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:41

    Both are correct and equally efficient. Using one of those instead of a plain array is only to ease memory management and passing them as argument.

    I use vector because the intention is more clear than with string.

    Edit: C++03 standard does not guarantee std::basic_string memory contiguity. However from a practical viewpoint, there are no commercial non-contiguous implementations. C++0x is set to standardize that fact.

提交回复
热议问题