Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
Can't write object to file c++
Name: dave19 Date: December 5, 2008 at 05:33:00 Pacific OS: Windows XP SP2 CPU/Ram: Intel Duo Core 512 Product: Hewlett-packard / NX6310
Comment:
I'm trying to write an object to file "List.dat" using multiple I/O class object of fstream. It works when i open the file to write and read from it. But it doesn't seem to work when i open the file to read first to check the written objects before writing a new object to it.
Name: klint Date: December 5, 2008 at 08:44:22 Pacific
Reply:
What do you pass as the second argument (the openmode argument) to the fstream constructor?
(By the way, the fstream constructor is described on page 666 of the C++ Standard, so it must be a bit of a devil ;-)
0
Response Number 2
Name: dave19 Date: December 5, 2008 at 14:01:34 Pacific
Reply:
ios::in in open() for reading and for second time ios::out in open() for writing in file.
0
Response Number 3
Name: klint Date: December 8, 2008 at 06:40:11 Pacific
Reply:
When you open it the second time (i.e. for writing), you need to make sure you close it first. You can't open it if it is already open. Also, you should check the status of the file after opening (and before every read or write operation.) But you left me wondering why you've taken this approach. Normally, if you want to read and write the same file, you would open it for both read and write (passing ios::in | ios::out) or else you might as well create two objects, and ifstream and an ofstream.
0
Response Number 4
Name: dave19 Date: December 8, 2008 at 12:19:36 Pacific
Reply:
Thanks, I suppose It was missing the close() at the end, but then i thought to use two different objects to open it anytime for read or write.
Summary: The explanation of the different modes of file access is quite long. I would recommend you use Help in VB, sorry I can't point you to the exact examples because the help was not installed in my VB du...
Summary: Here's my dilemma of the day. I'm writing a batch program built around 7za.exe to xcopy files to a destination then zip the directories, replacing them. If I do a dir thus dir /b /a-d %path% >root.t...