我现在想产生一个Num[200]的数据,然后读入文件。由于初学,希望用代码回复

解决方案 »

  1.   


    #define MAX_COUNT 200
    int Num[MAX_COUNT] = {0}; CString strText(_T(""));
    CString strTmp(_T("")); srand((int)time(NULL));
    for(int i=0; i<MAX_COUNT; i++)
    {
    Num[i] = rand();
    strTmp.Format(_T("%d "), Num[i]);
    strText += strTmp;
    if(0 == (i+1)%10)
    {
    strText += _T("\r\n");
    }
    } try
    {
    CStdioFile file;
    file.Open(_T("F:\\11.txt"), CFile::modeCreate | CFile::modeWrite);
    file.WriteString(strText);
    file.Close();
    }
    catch (CFileException* e)
    {
    e->ReportError();
    e->Delete();
    }
      

  2.   

    正好有一个,贴出来会不会不道德呀,我怕被BS呢~~
    long int a[200];
    ofstream fout("random.txt"); 
    srand((unsigned)time(NULL));
    for (int i=0;i<200;i++)
    {
    long int temp=(rand()*rand())%MAX;
    a[i]=temp;
    fout<<temp<<endl;
    }
    cout<<"随机数产生完毕!"<<endl;
    fout << flush; 
    fout.close();