Thread View: gnu.gcc.help
2 messages
2 total messages
Started by Maya
Tue, 04 Mar 2003 19:37
About persistance
Author: Maya
Date: Tue, 04 Mar 2003 19:37
Date: Tue, 04 Mar 2003 19:37
40 lines
2963 bytes
2963 bytes
Hi!
Can someone please tell me what I am doing wrong in he below example.
I really can't get it. I copied this from a book, and then adapted it to
my class, why is it not working?
class Date{
int month;
.........
public:
void Write(std::fstream&);
std::streampos Read(std::fstream&, std::streampos);
};
void Date::Write(std::fstream& rfs)throw(jme::Exception, jme::FileIOEx) {
rfs.write(reinterpret_cast<char*> (&month), sizeof(month));
}
std::streampos Date::Read(std::fstream& rfs,
std::streampos offset = std::ios::beg)
throw(jme::Exception, jme::FileIOEx) {
char buffer[sizeof(size_t)];
rfs.flush();
rfs.seekp(offset);
rfs.read(buffer, sizeof(int) );
if(rfs.fail()){ std::cout << "Error\n";} // <== This gets displayed
return rfs.tellp();
}
--
====================== E-Communications Canada =====================
Jorge Escalante - Software Development Coordinator.
E-Mail Policy http://www.vif.com/users/escalante/Email_Policy.html
* You cannot exercise your power to a point of humiliation of others.
* What does an elephant do when he gets a broken toe?
-He calls a toetruck
Re: About persistance
Author: osmium
Date: Tue, 04 Mar 2003 22:18
Date: Tue, 04 Mar 2003 22:18
11 lines
1489 bytes
1489 bytes
Maya writes: > Can someone please tell me what I am doing wrong in he below example. > I really can't get it. I copied this from a book, and then adapted it to > my class, why is it not working? <snip> I don't have time to look at it. But did you remember to 'rewind' after the write and before the read? Forgetting is a common error.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads