vc++取随机数

来源:百度知道 编辑:UC知道 时间:2024/06/16 22:17:24
#include<iostream.h>
#include<ctime>
void main(){
srand((unsigned)time(NULL));
int i;
i=rand()%10;
cout<<i<<endl;
}
问这段程序哪错了?
error C2065: 'srand' : undeclared identifier
error C2065: 'rand' : undeclared identifier
谁能解释一下并教我怎么做随机数?
加上就连它一起错误了。。

加一句
using namespace std;
改一下,以下代码在dev-c++编译通过
=========================
#include<iostream>
#include<ctime>
using namespace std;
int main(){
srand((unsigned)time(NULL));
int i;
i=rand()%10;
cout<<i<<endl;
getchar();
return 0;
}