Topic: FSTREAMS: unopened file, what state is the stream in?


Author: "Chris P. Randle" <randle@cig.mot.com>
Date: 1996/07/25
Raw View
Is it written what state a fstream object is in when newly created?

Given:
 ifstream in;

 //??? Is there a test that indicates the file is not
 // attached to a Filebuff object

I would like to know this information so that I can perform a test
on a file stream to determine if it has been previously open (if it
has been open, then close the file and reopen a different file).

Thanks!
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: Paul Evans <evansp@entcf3.agw.bt.co.uk>
Date: 1996/07/25
Raw View
Chris P. Randle wrote:
>
> Is it written what state a fstream object is in when newly created?
>
> Given:
>         ifstream in;
>
>         //??? Is there a test that indicates the file is not
>         // attached to a Filebuff object
>
> I would like to know this information so that I can perform a test
> on a file stream to determine if it has been previously open (if it
> has been open, then close the file and reopen a different file).

// ...

if (in.is_open()) {
    in.close();
}
in.open(name, mode, prot);

// ...


paul
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]