Ofstream Junk values!

Hey,
I wish to output the results of my program onto an output file. Hence I create an ofstream object as follows;

ofstream output ("Output.txt");

Then I print the value for the initial conditions of my problem as,

printf("\n%f", t);

Now, whenever i comment out the declaration of ofstream object, the initial value of t printed is correct (0.0). when i uncomment it, I get a value printed (8.546) which is apparently junk. No other changes are made to the code.

I do not know the source of this error. Also, the results are not getting printed into the output file.

Thanks,
Ajinkya
Last edited on
The printf call writes to a FILE *, in this case to standard out (stdout). Streams do not work with printf -- you should use one of the functions of ofstream to write to your file.
printf() is C; ofstream is C++. Don't mix them.

What is t??? Because the ofstream is called output. I just don't see the relation.
Topic archived. No new replies allowed.