64,642
社区成员
发帖
与我相关
我的任务
分享
段错误(核心已转储)
#include <iostream>
#include <cstdlib>
#include <fstream>
using namespace std;
const static int TOTALCOUNT = 1000000;
const static int MAXNUM = 10000000;
int numFlag[TOTALCOUNT+1];
int main()
{
int numCount = 0;
ofstream fout;
fout.open("source.txt");
if(!fout)
{
cout<<"Cannot create the source file."<<endl;
return 0;
}
while(numCount < TOTALCOUNT)
{
int r = rand() % MAXNUM + 1;
if(numFlag[r] == 0)
{
numFlag[r] = 1;
fout<<r<<endl;
cout<<r<<endl;
numCount++;
}
}
fout.close();
return 1;
}