When would you use an array rather than a vector/string?

前端 未结 8 2052
醉梦人生
醉梦人生 2020-12-01 19:09

I\'m a beginner C++ programmer and so I\'ve learnt using arrays rather than vectors (this seems to be the general way to do things, then move on to vectors later on).

<
8条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-01 19:49

    I see two reasons:

    1. Compatibility (old code without STL).
    2. Speed. (I compared the speed of using vector/binary_search & array/handwritten binary search. For the last one ugly code was obtained (with reallocation of memory), but it was about 1.2-1.5 times faster then first one, I used MS VC++ 8)

提交回复
热议问题