无法解决的功能'srand'?(我正在使用 Ubuntu OS 和 Eclipse)

Function 'srand' could not be solve? (i'm using Ubuntu OS and Eclipse)

本文关键字:Ubuntu OS Eclipse 解决 功能 srand      更新时间:2023-10-16

这是我第一次使用Eclipse进行C++编程,我遇到了一个问题。我已经包含了"time.h",但错误(函数"srand"无法解决)仍然出现。请帮帮我!非常感谢

#include "iostream"
#include "time.h"
using namespace std;
#define MAX 100
void InputArray(int a[],int n)
{
    srand((unsigned)time(NULL)); //error here Function 'srand' could not be solved
        a[0]=rand()%10; //and here 
        for(int i=1; i<n; i++)
            a[i]=a[i-1] + rand()%10 + 1;
}
int main() {
    int a[MAX], n;
    InputArray(a,n);
    return 0;
}

您忘记了

#include <stdlib.h>