0

I have a c++ function which returns std::vector of integer. I need to save all the values in vector to array for using it in C multiple functions

How can I convert vector to std array, I want array to be static

int* getGroupIds()
{
//Do code refactor for effcient access
vector<uint32_t> vec_groupIDs = m_scanConfig->GetGroupIds();
const int size = vec_groupIDs.size();
int arr[size];
std::copy(vec_groupIDs.begin(), vec_groupIDs.end(), arr);

return arr;
}
Sijith
  • 3,740
  • 17
  • 61
  • 101
  • 2
    *"vector to std array"*. You probably mean C-array, as `std::array` is not C either. – Jarod42 Jan 22 '19 at 08:48
  • Strictly speaking you cannot use an array in a C function because it's impossible to pass an array to a function in C (or C++). What you do instead is pass a pointer to the first element of the array. It's easy to get a pointer from a vector (see linked answer) but if you really want a static array then you're going to have to decide how big to make that array and what to do if the vector is bigger than the array, See linked answer for how to copy a vector to an array. – john Jan 22 '19 at 08:53

0 Answers0