このコードに問題があります。
コードで探しているのは、「first」と「second」の結果をランダムに取得し、結果をファイルに入れることです。
ファイルを使用せずに実行すると、すべて正しい結果が得られますが、結果をファイルに保存しようとすると、(first、secnd) を含む最初のノードしか得られません。
コードは次のとおりです。
#include<iostream>
#include <fstream>
#include<cmath>
using namespace std;
void main()
{
int first[100],secnd[100];
for (int i=0; i<100 ;i++)
{
first[i]=rand()%500; //random number from to 499
secnd[i]=rand()%500; //random number from to 499
ofstream myfile;
myfile.open ("example.txt");
myfile << "Writing this to a file.\n";
myfile <<first[i]<<" "<<secnd[i];
myfile.close();
}
}