[英]C++ cast std::vector<char*> to char**
How can I cast or convert a std::vector to char** in C++? 如何在C ++中将std :: vector 转换或转换为char **?
I'm using std::vector because I need to push_back some strings inside a loop, but then I have to call a C function that requires a char**. 我使用std :: vector的原因是我需要在循环中将一些字符串push_back回退,但是随后我必须调用一个需要char **的C函数。
std::vector::data
will produce char**
, although this pointer can get invalidated if reallocation happens on the vector. std::vector::data
将产生char**
,尽管如果在矢量上发生重新分配,则此指针可能会失效。
Also, &vec[0]
is another technique for producing a mutable pointer, but you need to be careful with this approach. 同样,
&vec[0]
是用于生成可变指针的另一种技术,但是在使用这种方法时需要小心。
Use the data method for this : http://en.cppreference.com/w/cpp/container/vector/data 为此,请使用数据方法: http : //en.cppreference.com/w/cpp/container/vector/data
which will return a pointer to the vectors data 这将返回指向矢量数据的指针
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.