View Full Version : writing and appending to file lots of times takes to long how to improve ?

05-20-2008, 02:52 PM
Hello all

im using ofstream to writing to file and then appending strings to file

the problem is that im writing to file many times some thing like 5000+ times ( the reason is it writing to file directories and files )

the code open file and writing to it looks like this :

ofstream myfile ("my_log.txt",ios::app);

if (myfile.is_open())


myfile << c <<".\n";



how can i improve the speed of writing to file ?

05-20-2008, 03:35 PM
Don't open and close it so much. Open it once and leave it open until you are done.

05-20-2008, 06:35 PM
can i close the file only when the application exit ?

05-20-2008, 08:23 PM
Yeah or when you've done your 5,000 writes or whatever. Just make sure you do close it at some point.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum