C++ SDL_JoystickName 中的整数索引

Integer index in SDL_JoystickName in C++

看下面的简单代码:

int main()
{
    int a;
    a = SDL_Init(SDL_INIT_JOYSTICK);
    a = SDL_NumJoysticks();
    for (int i=0; i<a; i++)
        cout << SDL_JoystickName(i);
    return 0;
}

我正在使用 SDL 库,代码似乎没有问题,我正在尝试获取连接的操纵杆的名称,但它给了我以下错误:

error C2664: 'SDL_JoystickName' : cannot convert parameter 1 from 'int' to 'SDL_Joystick *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast

问题出在哪里?

文档指出 SDL_JoystickName 接受一个 SDL_Joystick* 作为参数(编译器说的一样) 您可以通过 SDL_JoystickOpen 检索 SDL_Joystick*,它将 int 作为参数。

https://wiki.libsdl.org/SDL_JoystickName

编辑:正如 Joachim Pileborg 所说,如果您只想检索名称,SDL_JoystickNameForIndex 是可行的方法