help with write to .txt file
Hi everyone,
need some help, this function doesnt work for me and I dont know why, maybe you can help me.
Code:
void menu4(double array[], int n) {
ofstream results("results.txt");
for (int i = 0; i < n ; i++)
{
results << array[i] << " ";
cout << array[i] << endl;
}
results << endl;
}
'cout' is printing the array elements, but in file i dont see nothing
Re: help with write to .txt file
You're not closing the output file. I wouldn't bet on the data being written out properly without that.
Re: help with write to .txt file
The closes "automatically" when the ofstream object goes out of scope.
Viggy
Re: help with write to .txt file
Quote:
Originally Posted by
MrViggy
The closes "automatically" when the ofstream object goes out of scope.
Oh, thanks. :o I'll try to memorize tha now.
So I think first the OP should check whether the file gets opened correctly at all before writing to it. Perhaps there's some sort of permission issue?