How can I convert a std::vector<float> to a float array? [duplicate]
Possible Duplicate:
Getting array from std:vector
I've been reading the answers to this question and found them useful, but how can I do the same with a float type?
The same thing.
std::vector<float> v(10);
float *p = &v[0];
In exactly the way econoclast demonstrated on the answer you quoted.
std::vector<float> v;
v.push_back(1.2);
v.push_back(3.4);
// &v[0] is a pointer to the first element of the vector.
float* array_sort_of = &v[0];
for (size_t i = 0; i < 2; i++) {
std::cout << array_sort_of[i] << " ";
}
// Output: 1.2 3.4
精彩评论