srand(time(NULL)):错误 C4430:缺少类型说明符 - 假定为 int.注意:C++不支持默认整数
srand(time(NULL)): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
我试图为 rand() 函数播种
为什么我总是得到与 rand() 相同的随机数序列?
#include "stdafx.h"
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>
#include <windows.h>
#include <string>
#include <shlobj.h>
#include <Shlwapi.h>
#include <stdio.h>
#include <aclapi.h>
#include <tchar.h>
#include <iostream>
#include <fstream>
#include <curl/curl.h>
#include <future>
#include <stdlib.h>
#include <random>
#include <ctime>
#include <time.h>
#include <Lmcons.h>
srand(time(NULL));
int random_integer = std::rand();
但是 srand(time(NULL)) 返回:
错误 C4430:缺少类型说明符 - 假定为 int。注意:C++不支持默认整数
错误 C2365:"srand":重新定义;以前的定义是"函数"
现在的问题是调用srand(time(NULL));
需要进入函数内部 - 在全局范围内,你不能只编写将执行的代码 - 你只能声明/定义函数,变量等。
定义可以包括初始值设定项,这是允许int random_integer = std::rand();
工作的原因。
一种明显的治疗方法:
int radom_integer;
int main() {
srand(time(NULL));
random_integer = rand();
// ...
}
也就是说,您通常最好使用 C++ 随机数生成器类而不是 srand
/rand
。
相关文章:
- 为什么在全局范围内使用"extern int a"似乎不行?
- int(c) 和 c-'0' 之间的区别。C++
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 为什么野牛仍在使用"int yylex(void)",却找不到"int yylex(YYS
- 有符号的int和int-有没有一种方法可以在C++中区分它们
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 是否可以从int转换为enum类类型
- 不能在初始值设定项列表中将非常量表达式从类型 'int' 缩小到'unsigned long long'
- 缺少类型说明符 - 假定为 int.注意 c++ 不支持 default-int
- 错误:C4430:缺少类型说明符-假定为int.注意:C++不支持default-int
- 错误C4430:丢失类型指定词 - 假设INT.注意:C 不支持对我的构造函数的默认设置
- CREATESTRUCT错误C4430:缺少类型说明符-假定为int.注意:C++不支持默认的int C:xdc
- 错误 1 错误 C4430:缺少类型说明符 - 假定为 int.注意:C++不支持默认整数
- 模板类:错误 C4430:缺少类型说明符 - 假定为 int.注意:C++不支持默认整数
- 错误 C4430、C2146 - 缺少类型说明符 - 假定为 int.注意:C++不支持默认整数
- srand(time(NULL)):错误 C4430:缺少类型说明符 - 假定为 int.注意:C++不支持默认整数
- 这是什么意思?:注意:参数 1 没有从"int"到"const 帐户"的已知转换
- VC++缺少类型说明符-假定为int.注意:C++不支持default-int
- C2143 缺少 '*' 之前的';' 和 C 4430 缺少类型说明符 - 假定为 int。注意 C++ 不支持 default-int
- 错误c4430缺少类型说明符-假定为int.注意:c++不支持default-int生成器