fstream::open problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Belebele

    fstream::open problem

    The code below does not cause an assertion failure.

    fstream f;
    f.open("myfile" );
    assert( f.is_open() );



    However, the one below does fail the assert:

    fstream f;
    f.open("myfile" , ios::in | ios::out | ios::app);
    assert( f.is_open() );


    Any idea why?


    Thanks:
    Belebele

  • Victor Bazarov

    #2
    Re: fstream::open problem

    Belebele wrote:
    The code below does not cause an assertion failure.
    >
    fstream f;
    f.open("myfile" );
    assert( f.is_open() );
    >
    >
    >
    However, the one below does fail the assert:
    >
    fstream f;
    f.open("myfile" , ios::in | ios::out | ios::app);
    assert( f.is_open() );
    >
    >
    Any idea why?
    'ios::app' cannot be combined with 'ios::in' (27.8.1.3/2).

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask


    Comment

    • Belebele

      #3
      Re: fstream::open problem


      Victor Bazarov wrote:
      'ios::app' cannot be combined with 'ios::in' (27.8.1.3/2).
      Does that mean that I cannot read from the file if I want to append?
      Will I retain the capability to read from the file if I remove ios::in?

      Also, what does the numbers mean at the end of your line mean? Some
      link into a document somewhere? (I have looked in many places ...)

      Thanks:

      AQ

      Comment

      • Victor Bazarov

        #4
        Re: fstream::open problem

        Belebele wrote:
        Victor Bazarov wrote:
        >'ios::app' cannot be combined with 'ios::in' (27.8.1.3/2).
        >
        Does that mean that I cannot read from the file if I want to append?
        No, you just can't rely on the appending capabilities of the streams
        if you want to be reading from the same file.
        Will I retain the capability to read from the file if I remove
        ios::in?
        No. I suggest you just use 'in' and 'out', and perform positioning
        of the stream yourself.
        Also, what does the numbers mean at the end of your line mean? Some
        link into a document somewhere? (I have looked in many places ...)
        They are the chapter[.section[.subsection]]/paragraph of the Standard.
        If you want to get a copy, see the FAQ where to get it.

        V
        --
        Please remove capital 'A's when replying by e-mail
        I do not respond to top-posted replies, please don't ask


        Comment

        Working...