'How to return vector from C++ function and read using Python ctypes

I'm having a C++ function which is returning of type vector.

Example:

std::vector<std::string> exampleFunction() {
    std::vector<std::string> vec;
    # intermediate code
    return vec;
}

Now I need to call this function exampleFunction after importing the C++ built file. The return of exampleFunction, vector I need to access. I tried defining the structure like below in Python

class tempStructure(Structure):
    _fields_ = [("vec", POINTER(c_char_p)]

but this is not helping me to get the full vector array. With this, I'm able to access only the first item of the vector through this. How to access the full array?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source