ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi people, I have written a program that does some calculations (if you care, it approximates a definite integral using both Simpson's rule and the trapezium rule for different numbers of sub-intervals, along with relative errors) and is supposed to output the results to both the screen and to a file. It outputs the results to the screen fine, but it seems to only write the last set of results to the file:
two options
a:
write all the data to a stream, open the file "<<" direct it into the file and flush, close the file.
b:
open the with the ios::app flag to append to the end of the file.
Im unsure to be honest i normaly collect the data and then direct it to file, or as i suggested append to the file.
You really should close the file tho and its a good idea to flush so that you empty the stream.
it should work theres not any real diffs i can see from a piece of my code.
Nylex, the way you are writing to the file should work. Like dmail suggested you could try to flush the buffer..
out.flush()
after every write and see what happens..
i may be mistaken but i think that fstream destructor will close the file and you do not have to explicitly close it unless you would want to reopen a file with that stream var..
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.