std :: vector到本机数组 [英] std::vector to native array
本文介绍了std :: vector到本机数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为此原型提供功能
Given a funcition with this prototype
void Func(int* elements, int count);
这是
Is this
vector<int> v;
v.push_back(1);
Func(&*v.begin(), v.size());
安全的?还是应该给Func打电话?以可移植的方式,我的意思是.向量可以通过某种方式保证数组的内存空间吗?
safe? Or how should I call Func? In a portable way, I mean. Does vector guarantee the memory layot of my array in some way?
推荐答案
安全!
确保向量的元素连续存储.
Safe!
It''s guaranteed that the elements of a vector are stored contiguously.
http://www.cplusplus.com/reference/stl/vector/
这篇关于std :: vector到本机数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文