编写程序产生1000个取值范围在100-999之间的随机整数

编写程序产生1000个取值范围在100-999之间的随机整数,并将这些整数以文本格式写入到c:\data3.txt中。

老师给的作业,我使用的系统不一样,知道题的解法但不知道代码怎么写,求代码谢谢

#include <iostream>
#include <fstream>
#include <time.h>

using namespace std;


int main()
{
    srand((unsigned int)time(NULL));
    ofstream outfile;
    outfile.open("c:\\data3.txt");
    int n;
    for(int i=0;i<1000;i++)
    {
        n=rand()%900+100;
        outfile << n << " ";

    }
    outfile.close();

    return 0;
}

 

注:将整数写入到一个文本文件格式数据文件时,应在写入每个数据之后输出换行符"endl",或者一个空格,即如以下的代码:

outfile<<x<<endl;

或:

outfile<<x<<" ";