Hi all,
I got a 'problem' with the following code (using STL):
ifstream * f = new ifstream("filename.bmp", ios_base::binary);
It would create the object (f is different from NULL), but it wouldn't
pass the parameters to the constructor (f->is_open() returns false
even though the file exists, etc.) as I expected.
Is this a bug/feature of my compiler or something more standard in
C++?
Hector.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
hhcalderon
|
7/16/2003 8:45:08 PM |
|
> >
> What mkaes you think the parameters never amde it to the constructor?
> Any chance the file is protected against you or otherwise not openable.
> Any chance you screwed up the filename? Can you open it with stdio
> (fopen)?
>
Because
ifstream * f = new ifstream("filename.bmp", ios_base::binary);
doesn't work, but
ifstream * f = new ifstream;
f->open("filename.bmp", ios_base::binary);
does work!!!
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
hhcalderon
|
7/18/2003 12:02:05 PM
|
|
Ray Lischner <rl.news@tempest-sw.com> writes:
> On Wednesday 16 July 2003 01:45 pm, Hector wrote:
>
>> ifstream * f = new ifstream("filename.bmp", ios_base::binary);
>
> Among the file modes, you must supply ios_base::in, ios_base::out, or
> both.
No. 27.8.1.6/2 specifies that this ifstream constructor will bitwise
or the supplied mode with ios_base::in . So ios_base::in is
uneccessary. I can't figure out what the effect of supplying
ios_base::out is supposed to be, but I bet it is undefined.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
llewelly
|
7/21/2003 7:30:53 PM
|
|
In article <1d7a.3f16b366.8261c@prospero.island.local>,
Ray Lischner wrote:
> On Wednesday 16 July 2003 01:45 pm, Hector wrote:
>
>> ifstream * f = new ifstream("filename.bmp", ios_base::binary);
>
> Among the file modes, you must supply ios_base::in, ios_base::out, or
> both.
The standard says that the ifstream constructor will add the ios_base::in
mode, and similarly the ofstream constructor will add the ios_base::out
mode, so this should not be necessary. In practice I believe there are
some implementations that fail to do this.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
Ben
|
7/21/2003 8:11:18 PM
|
|
Ray Lischner <rl.news@tempest-sw.com> wrote in message
news:<1d7a.3f16b366.8261c@prospero.island.local>...
> On Wednesday 16 July 2003 01:45 pm, Hector wrote:
> > ifstream * f = new ifstream("filename.bmp", ios_base::binary);
> Among the file modes, you must supply ios_base::in, ios_base::out, or
> both.
According to the standard, ifstream is supposed to or ios::in in.
--
James Kanze GABI Software mailto:kanze@gabi-soft.fr
Conseils en informatique orient�e objet/ http://www.gabi-soft.fr
Beratung in objektorientierter Datenverarbeitung
11 rue de Rambouillet, 78460 Chevreuse, France, +33 (0)1 30 23 45 16
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
kanze
|
7/21/2003 11:35:58 PM
|
|
hhcalderon@yahoo.com (Hector) wrote in message news:<e64dc7b5.0307151607.36af0a73@posting.google.com>...
> Hi all,
>
> I got a 'problem' with the following code (using STL):
>
> ifstream * f = new ifstream("filename.bmp", ios_base::binary);
>
> It would create the object (f is different from NULL), but it wouldn't
> pass the parameters to the constructor (f->is_open() returns false
> even though the file exists, etc.) as I expected.
>
> Is this a bug/feature of my compiler or something more standard in
> C++?
After reading your kind replies, it looks like I found yet another bug
in a Microsoft product!!!
Hector C.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
hhcalderon
|
7/23/2003 11:13:06 PM
|
|
In article <e64dc7b5.0307221930.5c746da2@posting.google.com>,
on 23 Jul 2003 19:13:06 -0400,
hhcalderon@yahoo.com (Hector) wrote:
> hhcalderon@yahoo.com (Hector) wrote in message
> news:<e64dc7b5.0307151607.36af0a73@posting.google.com>...
> > Hi all,
> >
> > I got a 'problem' with the following code (using STL):
> >
> > ifstream * f = new ifstream("filename.bmp", ios_base::binary);
> >
> > It would create the object (f is different from NULL), but it wouldn't
> > pass the parameters to the constructor (f->is_open() returns false
> > even though the file exists, etc.) as I expected.
> >
> > Is this a bug/feature of my compiler or something more standard in
> > C++?
>
> After reading your kind replies, it looks like I found yet another bug
> in a Microsoft product!!!
Whch header are you including (<fstream> or <fstream.h>)?
The version of std::ifstream which ships with MSVC 6 "does the right
thing" (see line 264 of <fstream>). I can't say for sure what the "old"
(fstream.h) ifstream implementation does (or, for that matter, what it's
supposed to do :)
Regards,
Andy S
--
"Light thinks it travels faster than anything but it is wrong. No matter
how fast light travels it finds the darkness has always got there first,
and is waiting for it." -- Terry Pratchett, Reaper Man
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
Andy
|
7/26/2003 1:41:22 PM
|
|
|
6 Replies
588 Views
(page loaded in 0.082 seconds)
Similiar Articles: fstream and fopen difference? - comp.lang.c++.moderatedHi I wonder if someone can tell me the difference between using fstream class and file ... to use the C++-style, for its integrated type safety and for the adaptation to new ... comp.lang.c++.moderated - page 12new fstream isn't a weirdo, is it? 6 268 (7/16/2003 8:45:08 PM) Hi all, I got a 'problem' with the following code (using STL): ifstream * f = new ifstream("filename.bmp ... Difference between community and standard edition - comp.databases ...There are rumors that in the future Oracle will put some new features into the ... VHDL-2002 vs VHDL-93 vs VHDL-87? - comp.lang.vhdl... but I can't seem to find a ... Best design for my classes to avoid code duplication? - comp.lang ...ADevice::ADevice () : m_protocol (new AProtocol ... looks of things, you could use a template: Isn't ... (You might start by looking at something like std::fstream ... input & output in assembly - comp.lang.asm.x86It really isn't that difficult, and it can save you ... Probably so, but you don't start new pilots off in a 747. ... more sense, in that I only have to posit /one/ weirdo ... cannot write std::map via ostream_iterator? - comp.lang.c++ ...... global) doesn't help, beacuse that namespace isn't ... Use the new type as a parameter to ostream ... snip] #include <iostream> #include <fstream> #include ... [ace-users] ACE 5.7.7 iPhone 3.1.2 hardware build does not build ...... link to a platform-specific file, simply state which one (unless this isn't used ... iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.2.sdk/usr/include/c++/4.2.1/new:45 ... top 10 uses for random data compression?? anyone? - comp ...That it isn't about what is there but about what ... of the testy souths, but don't push the new ... poor, so I change you. My holy primary won't restore before I creep ... DSP Job opening in Sacramento, CA - comp.dspGuarding the borders isn't going to change that. ... C'mon: there even was a city mayor (I don't recall if it was New ... of course), their language rides -- it doesn't creep ... fstream and fopen difference? - comp.lang.c++.moderated | Computer ...Hi I wonder if someone can tell me the difference between using fstream class and file ... to use the C++-style, for its integrated type safety and for the adaptation to new ... fstream.h, I thought it was a standard header.... | DaniWebStart New Discussion Reply to this Discussion ... fstream is part of the C++ standard, fstream.h isn't. The difference between fstream and fstream.h 7/25/2012 12:41:05 AM
|