| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3504 人关注过本帖
标题:关于srand(time(0));的错误
只看楼主 加入收藏
cstdio
Rank: 5Rank: 5
来 自:上海市静安区
等 级:贵宾
威 望:15
帖 子:97
专家分:44
注 册:2018-5-30
结帖率:87.5%
收藏
已结贴  问题点数:20 回复次数:7 
关于srand(time(0));的错误
srand(time(0))如果包含ctime就会在using ::clock出错
搜索更多相关主题的帖子: srand time 错误 using 出错 
2018-07-17 13:40
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:20 
贴出代码,贴出编译器给的错误信息,此外无它

程序代码:
#include <cstdlib>
#include <ctime>

int main( void )
{
    srand( static_cast<unsigned>(time(nullptr)) );
}

2018-07-17 14:40
cstdio
Rank: 5Rank: 5
来 自:上海市静安区
等 级:贵宾
威 望:15
帖 子:97
专家分:44
注 册:2018-5-30
收藏
得分:0 
60    11    C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\ctime    [Error] '::tm' has not been declared
62    11    C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\ctime    [Error] '::clock' has not been declared
63    11    C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\ctime    [Error] '::difftime' has not been declared
64    11    C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\ctime    [Error] '::mktime' has not been declared
65    11    C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\ctime    [Error] '::time' has not been declared
66    11    C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\ctime    [Error] '::asctime' has not been declared
67    11    C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\ctime    [Error] '::ctime' has not been declared
68    11    C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\ctime    [Error] '::gmtime' has not been declared
69    11    C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\ctime    [Error] '::localtime' has not been declared
70    11    C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\ctime    [Error] '::strftime' has not been declared
6    39    C:\1.cpp    [Error] 'nullptr' was not declared in this scope
6    46    C:\1.cpp    [Error] 'time' was not declared in this scope

import random
i=random.randint(100,100000)
print i
2018-07-18 10:17
cstdio
Rank: 5Rank: 5
来 自:上海市静安区
等 级:贵宾
威 望:15
帖 子:97
专家分:44
注 册:2018-5-30
收藏
得分:0 
dev_c++ 32bit release

import random
i=random.randint(100,100000)
print i
2018-07-18 10:17
cstdio
Rank: 5Rank: 5
来 自:上海市静安区
等 级:贵宾
威 望:15
帖 子:97
专家分:44
注 册:2018-5-30
收藏
得分:0 
重装好多遍都没有用
包含ctime的文件都会编译错误

import random
i=random.randint(100,100000)
print i
2018-07-18 10:18
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:0 
回复 3楼 cstdio
贴代码,贴代码,贴代码!
如果你用的是2楼给出的代码,你要明确、明确、明确地说出来,不要无聊地打哑谜。

先说“[Error] 'nullptr' was not declared in this scope”吧,你用的编译太老旧了,那就将 nullptr 改为 NULL 吧。
其它的错误,看看你工程目录下是不是有个 time.h 文件,导致编译器错误地include了你这个time.h,而不是系统的time.h
2018-07-18 12:56
cstdio
Rank: 5Rank: 5
来 自:上海市静安区
等 级:贵宾
威 望:15
帖 子:97
专家分:44
注 册:2018-5-30
收藏
得分:0 
我用的就是2楼的代码
没有time.h文件啊

import random
i=random.randint(100,100000)
print i
2018-07-18 13:42
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:0 
回复 7楼 cstdio
那你换个目录重建工程试试
2018-07-18 14:35
快速回复:关于srand(time(0));的错误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014917 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved