Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #6275
| From | ruben safir <ruben@mrbrklyn.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: fstream - clobbering |
| Date | Mon, 06 Jun 2011 06:10:16 -0400 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Lines | 53 |
| Message-ID | <isi928$i22$1@reader1.panix.com> (permalink) |
| References | <isi2c8$flj$1@reader1.panix.com> <seekp-20110606103912@ram.dialup.fu-berlin.de> |
| NNTP-Posting-Host | www2.mrbrklyn.com |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 8bit |
| X-Trace | reader1.panix.com 1307355016 18498 96.57.23.82 (6 Jun 2011 10:10:16 GMT) |
| X-Complaints-To | abuse@panix.com |
| NNTP-Posting-Date | Mon, 6 Jun 2011 10:10:16 +0000 (UTC) |
| User-Agent | Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110414 SUSE/3.1.10 Thunderbird/3.1.10 |
| In-Reply-To | <seekp-20110606103912@ram.dialup.fu-berlin.de> |
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.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++:6275 |
Show key headers only | View raw
On 06/06/2011 04:40 AM, Stefan Ram wrote:
> ruben safir<ruben@mrbrklyn.com> writes:
>> I don't think that std::ios::binary clobbers the file and
>> all_quest.seekp( 0, std::ios_base::end);
>
> »seekp« seem to be defined using »pubseekoff« in ISO/IEC
> 14882:1998(E), which is defined in terms of »seekoff«,
> which is defined based on »::std::fseek«.
>
> ISO/IEC 9899:1990 explains about »fseek«:
>
> »A binary stream need not meaningfully support
> fseek calls with a whence value of SEEK_END.«
>
sigh
I get the gist of this. i finally got it to work by changing the code
to the following
void Deck::add_questions(Question &enter){
//open file
Deck tmp;
int pos;
std::ofstream all_quest( tmp.database.c_str(),
std::ios::binary|std::ios::app ); <========== Change
if(!all_quest){
std::cerr << "can't open question database for writing" << std::endl;
exit(1);
}
all_quest.seekp( 0, std::ios_base::end);
pos = all_quest.tellp();
std::cout << "We are at Pos ==>" << pos << std::endl;
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;
}
but if I'm understanding what you wrote, there is no means to do this
with portability.
Ruben
Back to comp.lang.c++ | Previous | Next — Previous 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