开发者

C++ random numbers

How can I use random numbers in Linux and C++?

I have found some code I would like to use, it has the line

srand((unsigned)time(0));//seed

but gcc s开发者_如何学编程ays

board.cpp:94:24: error: ‘time’ was not declared in this scope

I have included the following files

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <algorithm>


You'll need

#include <ctime>

to access the time function.


You haven't included the header that defines the function, in order for your program to know how to call time() you need to add this include:

#include <time.h>

and just to nitpick (code style) your call should more correctly be time(NULL) instead of time(0)


You need to include <time.h>


Indeed, It misses the include for the time function try :

#include <time.h>

you can go there to have a little more explanation about srand:

http://www.cplusplus.com/reference/clibrary/cstdlib/srand/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜