【发布时间】:2013-02-26 07:14:40
【问题描述】:
我用 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 ...}
我的问题是当我在命令行中通过编写调用程序时
name.exe 1 15 16 17
我得到 Xr = 15 但 Zr = 16 而 Yr 只是一个看似随机的巨大负数。
我知道这可能是一些非常基本的错误,但我无法找到是什么。感谢您的任何建议。
【问题讨论】:
-
这是预处理过的
c++吗?为什么main不是main? -
@Rubens:这是特定于 MS 的东西(
_tmain和PZWSTRforargv)。
标签: c++ command-line-arguments