vector vs string for binary data

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

    Is one more efficient than the other?

    This is the wrong question.

    Is one a more 'correct' usage?

    This is the correct question.
    It depends. How is the data being used? If you are going to use the data in a string like fashon then you should opt for std::string as using a std::vector may confuse subsequent maintainers. If on the other hand most of the data manipulation looks like plain maths or vector like then a std::vector is more appropriate.

    0 讨论(0)
  • 2020-12-05 07:54

    You should prefer std::vector over std::string. In common cases both solutions can be almost equivalent, but std::strings are designed specifically for strings and string manipulation and that is not your intended use.

    0 讨论(0)
  • 2020-12-05 07:55

    Compare this 2 and choose yourself which is more specific for you. Both are very robust, working with STL algorithms ... Choose yourself wich is more effective for your task

    0 讨论(0)
提交回复
热议问题