'random':找不到标识符错误

'random' : identifier not found error

本文关键字:错误 标识符 random 找不到      更新时间:2023-10-16

我正试图将为UNIX编写的代码移植到Visual studio,但收到以下错误

random.cpp(29): error C3861: 'initstate': identifier not found
random.cpp(37): error C3861: 'random': identifier not found
random.cpp(49): error C3861: 'random': identifier not found
random.cpp(51): error C3861: 'random': identifier not found
random.cpp(63): error C3861: 'random': identifier not found
random.cpp(78): error C3861: 'SQRT': identifier not found
random.cpp(78): error C3861: 'LOG': identifier not found
random.cpp(78): error C3861: 'COS': identifier not found
random.cpp(87): error C3861: 'ABS': identifier not found

代码很长,但我已经包含了math.h,但我仍然会遇到这些错误。这些函数可能只是UNIX!如果是,我有什么选择?

这是我的代码的一个修改过的示例(给我带来错误的行);

if( NULL == initstate(2, rngState, 256) )
    do something...
int r = (int)( (rangeEnd - rangeStart) * random() );
double z = SQRT(-2.0 * LOG(x1)) * COS(2.0 * M_PI * x2);

SQRT->sqrt

LOG->log

COS->cos

random->rand(别忘了# include <stdlib.h>

并在main之前写入initstate或进行正向声明。

包括stdlib.h并使用函数rand()。

此外,函数的名称使用小写cos、log、sqrt。