Re: What is the replacement for ios::noreplace in std?

Dennis_at_NoSpam.com
Date: 10/04/04


Date: Mon, 04 Oct 2004 16:21:15 GMT


"John Harrison" <john_andronicus@hotmail.com> wrote:

>> After working with this for quite a few days I've come to the conclusion
>> that
>> there is no good substitute for ios::noreplace.
>
>Why not? What was wrong with your solution (and mine)?

The reason the <fstream> replacement didn't work is complicated but I'll try and
explain. The calling program for my function where the <fstream> code is, puts
that function into a double loop. Each time it calls my function it's giving my
function a file to write to and the calculation results it wants to write in
that file. On the first pass for a given file the function opens a new file and
places a header as the first line in that file and the results on the next line.
On the next pass for a given file the function checks if that file exists with
the ios::noreplace and if the file exists it opens the file for append and
writes the next line. The calling program is writing to a 100+ files.

Now with <fstream> our method of opening the file for input, closing the file if
it exists and then opening the file for append just did not work. For some
reason the append did not work and the line after the header just keep getting
written over. So instead of 5000 lines plus header I ended up with just the
last calc line and a header. I tried many variations but all did not work. So
I went back to <fstream.h>

> After all I would be
>willing to bet that the implementation of noreplace in fstream.h is just
>more C++ code, so have a look in the header file at how they did it.
Hey this is a good idea I'll have to look at how the header implemented the
ios::noreplace.

As far as more code. My Program with <fstream.h> compiled into 108k. With the
<fstream> code my program compiled into 208k . Why the extra 100k? I don't
know. I'm using MS VC++ 6.0 with the latest SP.

>I think you mean 'for ( i=0; i<sMyString.size(); i++)'. Also you could
>consider
Right my typo.
>
>fdebug<<sMyString.c_str();

I tried this but <fstream.h> will not allow it.

Dennis



Relevant Pages

  • Replace write in fstream
    ... I'm trying to replace some bytes in a file using fstream but all I seem to ... be able to do is append or 0 the file then write... ... but it seems a waste to rewrite the same data for no reason). ...
    (comp.lang.cpp)
  • Re: Imagination
    ... I know of no reason I need to adjust my post to the level ... To limit spam harvesting it is not in the posting header. ... post exact recipes. ... But there is a real issue--- Diabetes has damaged my hands ...
    (alt.support.diabetes)
  • Re: Rejecting null sender from my clients
    ... As long as you put your real address in the From: header, ... The reason you'd want to use is if you want to avoid a bounce in ... correct DSN. ... blanket ban on as an envelope sender. ...
    (comp.mail.sendmail)
  • Re: where is a copy of atlstr.h ??
    ... > compilers, there is no reason, at all, for stdio.h to be a file. ... > with one previous version of Visual Studio, MFC and ATL headers were in ... A header is useless in isolation. ... > 1) If your position on missing header locations is so reasonable, ...
    (microsoft.public.vc.language)
  • Re: One to One - Multilple tables for large field qty
    ... If I add the third one-to-one, the primary key ... If you were advised to normalize your data, there's a reason. ... On the header table there is a form ID (primary ... joining the same FormID. ...
    (microsoft.public.access.tablesdbdesign)