Hello.
I have a problem writing to a file using for loop.
here is the code:
/* the code should save numbers in a file something like this
1 5
2 8
3 7
4 6
*/
//instead it gives just the last numbers it catches
/*
4 6
*/
for(int i=0;i<=4;i++){
//some code before
int iCom = (rand()%3+5);
ofstream played("played.txt");
if (played.is_open()){
played << i << " " << iCom;
played << endl;
played.close();
}
else cout << "Unable to save" << endl;
}
Thanks