标题:程序中有这样random和randomize头文件需要包含哪些?请指教
取消只看楼主
lindayanglong
Rank: 1
等 级:新手上路
帖 子:86
专家分:0
注 册:2008-3-9
 问题点数:0 回复次数:2 
程序中有这样random和randomize头文件需要包含哪些?请指教
我的程序中有这样random和randomize
头文件包含有:
#include<iomanip>
#include<cstdlib>
#include<iostream>
using namespace std;
但是总是出错:
'random' : undeclared identifier
 'randomize' : undeclared identifier
请高手指点。我把完整程序也贴在下面:
#include<iomanip>
#include<cstdlib>
#include<iostream>
using namespace std;

template<class T>
int linsearch(T *v,int N, T key)
{
    for(int i=0;i<N;i++)
    {if (v[i]==key)return i;}
    return -1;
}

inline int RandI(int N)
{
    return random(N)+1;
}

int main()
{
    int index;
    int key=32;
    randomize();
    const int size=20;
    int data[size];

    for(int i=0;i<size;i++)
        data[i]=RandI(85);
    cout<<"\ndata's value are :"
        <<endl;
    for( i=0;i<size;i++)
    {
        cout<<setw(10)<<data[i];
        if(i%5==4)cout<<endl;
    }
    index=linsearch(data,size,key);
    if(index>-1)
        cout<<key<<"is the "<<index+1
        <<"th palce"<<endl;
    else
        cout<<"cannot find "<<key<<endl;
    return 0;
}
搜索更多相关主题的帖子: random 文件 指教 
2008-07-15 10:08
lindayanglong
Rank: 1
等 级:新手上路
帖 子:86
专家分:0
注 册:2008-3-9
得分:0 
加上#include<ctime>还是一样啊
加上#include<ctime>还是上面的错误,请帮帮忙
2008-07-16 10:07
lindayanglong
Rank: 1
等 级:新手上路
帖 子:86
专家分:0
注 册:2008-3-9
得分:0 
十分感谢楼上的
2008-07-16 13:28



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-223918-1-1.html




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

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