Converting between C++ std::vector and C array without copying

前端 未结 5 1304
清酒与你
清酒与你 2020-12-02 08:34

I would like to be able to convert between std::vector and its underlying C array int* without explicitly copying the data.

Does std::vector provide access to the u

5条回答
  •  萌比男神i
    2020-12-02 09:12

    int* pv = &v[0]
    

    Note that this is only the case for std::vector<>, you can not do the same with other standard containers.

    Scott Meyers covers this topic extensively in his books.

提交回复
热议问题