gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 00:54:00 28 4
gpt4 key购买 nike

我用 C++ 编写了一个程序,它应该接受几个命令行参数,第一个是整数,其余三个是 float 。处理该问题的代码部分如下所示:

_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 ...}

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

name.exe 1 15 16 17

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

我知道这可能是一些非常基本的错误,但我一直无法找到究竟是什么。感谢您的任何建议。

最佳答案

您需要使用 %lf 转换来读取 double。您当前使用的 %d 仅适用于 int

关于c++ - 如何摆脱这个命令行参数错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15078281/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com