|
-
October 7th, 2011, 12:15 PM
#1
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
-
October 7th, 2011, 02:44 PM
#2
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.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
-
October 7th, 2011, 02:53 PM
#3
Re: help with write to .txt file
The closes "automatically" when the ofstream object goes out of scope.
Viggy
-
October 7th, 2011, 03:12 PM
#4
Re: help with write to .txt file
 Originally Posted by MrViggy
The closes "automatically" when the ofstream object goes out of scope.
Oh, thanks. 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?
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|