Writing into multiple files

Hi!

I have 2 questions about writing into multiple files:

1) Is there a more efficient way than opening and closing files everytime i am trying to write something in it?

2) Is there anyway the program can create multiple files depending on the number of objects instantiated during runtime? If there are 3 objects created then 3 files should be created and all the associated data is written into them, if 4 objects are created then 4 files are created. What would be a smart way to implement this if it is possible?

Thanks!
1) Is there a more efficient way than opening and closing files everytime i am trying to write something in it?

Yes. Simply open the file, and keep it open until you've finished all your writes. Then close it.

2) Is there anyway the program can create multiple files depending on the number of objects instantiated during runtime? If there are 3 objects created then 3 files should be created and all the associated data is written into them, if 4 objects are created then 4 files are created. What would be a smart way to implement this if it is possible?

Again, yes. Use a different fstream object for each file, and you'll be fine.
Last edited on
Topic archived. No new replies allowed.