Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #6264
| From | ruben safir <ruben@mrbrklyn.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | fstream - clobbering |
| Date | 2011-06-06 08:16 +0000 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Message-ID | <isi2c8$flj$1@reader1.panix.com> (permalink) |
I'm trying to figure out why the data file seems to be clobbered
void Deck::add_questions(Question &enter){
//open file
Deck tmp;
std::ofstream all_quest( tmp.database.c_str(), std::ios::binary );
if(!all_quest){
std::cerr << "can't open question database for writing" << std::endl;
exit(1);
}
all_quest.seekp( 0, std::ios_base::end);
std::cout << "value of enter.quest ============> \n\n" << enter.quest << "Size of string\n" << sizeof(char) *enter.quest.size() << std::endl;
all_quest.write(enter.quest.c_str(), sizeof(char) * enter.quest.size() );
all_quest.write(enter.answer.c_str(), sizeof(char) * enter.answer.size() );
all_quest.close();
return;
}
I don't think that std::ios::binary clobbers the file and
all_quest.seekp( 0, std::ios_base::end);
should be setting the the put pos at the end of the file.
Ruben
Back to comp.lang.c++ | Previous | Next — Next in thread | Find similar | Unroll thread
fstream - clobbering ruben safir <ruben@mrbrklyn.com> - 2011-06-06 08:16 +0000 Re: fstream - clobbering ruben safir <ruben@mrbrklyn.com> - 2011-06-06 06:10 -0400
csiph-web