Re: just a simple question re: ifstream
From: tlmseven (dabawenyo_at_gmail.com)
Date: 11/07/04
- Next message: John Harrison: "Re: Data Structure and making the size change"
- Previous message: dsa89: "Data Structure and making the size change"
- In reply to: Jonathan Turkanis: "Re: just a simple question re: ifstream"
- Next in thread: Peter Jansson: "Re: just a simple question re: ifstream"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 7 Nov 2004 07:51:04 -0800
"Jonathan Turkanis" <technews@kangaroologic.com> wrote in message news:<2v53aqF2g3la3U1@uni-berlin.de>...
> "tlmseven" <dabawenyo@gmail.com> wrote in message
> news:7443ffeb.0411061421.61258a2@posting.google.com...
> > I'm writing a simulator for my Comp Arch class, and I'm a bit rusty on
> > my C++ so I was wondering if anyone could help me out.
> >
> > We know that, when using ifstream to open a file for input, a file is
> > created by default if the specified filename in
> > ifstream("somefilename") does not exist.
>
> This is wrong. A file is never created in this case. Perhaps you are thinking of
> opening a file for writing with an ofstream, in which case the default behavior
> is to create a new file if one does not already exist.
>
> To disable this behavior, use an fstream and open it in default mode. To force a
> file to be created when using an fstream, use the flag ios::trunc.
>
> > How does one disable this default feature so that the program only
> > opens a file that does exist?
> >
> > Thanks to those of you who are willing to help.
>
> Jonathan
Well, the thing is it actually happened in real time. The program I'm
writing is a simulator for a PIC Chip and it prompts the user to enter
the filename of the hex file he/she would like to load into the
program. The code goes like:
void l(char filename[])
{
ifstream hexfile(filename[])
....
}
Now, I input a filename that did not correspond to any file in the
default directory I was saving to. Although it was an ifstream that
was declared, the program created a new file and attempted to read
"nothing" from this new file and subsequently crashed.
- Next message: John Harrison: "Re: Data Structure and making the size change"
- Previous message: dsa89: "Data Structure and making the size change"
- In reply to: Jonathan Turkanis: "Re: just a simple question re: ifstream"
- Next in thread: Peter Jansson: "Re: just a simple question re: ifstream"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|