From: ruben safir Newsgroups: comp.lang.c++ Subject: fstream - clobbering Date: Mon, 6 Jun 2011 08:16:08 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 32 Message-ID: NNTP-Posting-Host: www2.mrbrklyn.com Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: reader1.panix.com 1307348168 16051 96.57.23.82 (6 Jun 2011 08:16:08 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Mon, 6 Jun 2011 08:16:08 +0000 (UTC) User-Agent: Pan/0.133 (House of Butterflies) Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!feed.ac-versailles.fr!news.in2p3.fr!in2p3.fr!kanaga.switch.ch!switch.ch!newsfeed-00.mathworks.com!panix!not-for-mail Xref: x330-a1.tempe.blueboxinc.net comp.lang.c++:6264 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