简体   繁体   English

C ++向量指针指针

[英]C++ vector to pointer of pointers

Is there a way to convert a vector to a pointer to a pointer (ptr-to-ptr). 有没有办法将矢量转换为指针指针(ptr-to-ptr)。

Background: I have an arbitrary length set of data stored in a vector. 背景:我有一个存储在向量中的任意长度的数据集。 But I have a library of algorithms that accept ptr-to-ptr (for image array access). 但我有一个接受ptr-to-ptr(用于图像阵列访问)的算法库。 I need to get the data from my vector to a ptr-to-ptr. 我需要从我的向量中获取数据到ptr-to-ptr。 How is that possible? 怎么可能?

If you have a function void f(int **array) and a vector std::vector<int*> vect you can call f like this: f(&vect[0]) . 如果你有一个函数void f(int **array)和一个vector std::vector<int*> vect你可以像这样调用f: f(&vect[0]) Is this what you were looking for? 这是你在找什么?

Well, you can convert a vector to a const pointer-to-array using the c_str() member function. 好吧,你可以使用c_str()成员函数将向量转换为const指向数组。

EDIT: Oops! 编辑:哎呀! I meant &vec[0] . 我的意思是&vec[0] It's been a long day. 这是漫长的一天。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM