如何摆脱这个命令行参数错误?

San*_*uuu 1 c++ command-line-arguments

我用c ++编写了一个程序,它应该采用几个命令行参数,第一个是整数,其余三个是浮点数.处理它的代码部分看起来像这样:

_tmain(__in int argc, __in PZPWSTR argv)
{


    USHORT X, Y, Z, ZR, XR;                         // Position of several axes
    JOYSTICK_POSITION   iReport;                    // The structure that holds the full position data
    BYTE id=1;                                      // ID of the target vjoy device (Default is 1)
    UINT iInterface=1;                              // Default target vJoy device
    BOOL ContinuousPOV=FALSE;                       // Continuous POV hat (or 4-direction POV Hat)
    int count=0;
    DOUBLE Xr, Yr, Zr;


    // Get the ID of the target vJoy device
    if (argc>1 && wcslen(argv[1]))
        sscanf_s((char *)(argv[1]), "%d", &iInterface);

    sscanf_s((char *)(argv[2]), "%d", &Xr);
    sscanf_s((char *)(argv[3]), "%d", &Yr);
    sscanf_s((char *)(argv[4]), "%d", &Zr);

_tprintf("Acquired: X %d\nY %d\nZ %d\n", Xr, Yr, Zr);

the rest of the code ...}
Run Code Online (Sandbox Code Playgroud)

我的问题是,当我通过写入命令行调用程序时

name.exe 1 15 16 17
Run Code Online (Sandbox Code Playgroud)

我得到Xr = 15但是Zr = 16而Yr只是一些看似随机的巨大负数.

我知道这可能是一个非常基本的错误,但我无法找到它是什么.谢谢你的任何建议.

Jer*_*fin 6

您需要使用%lf转换来读取双精度数.该%d只为您目前使用是int秒.