fstream constructor

C

Chris Theis

Hello,

as stated by the standard the fstream derivatives (ifstream & ofstream)
expect a const char*
parameter indicating the file name associated with the stream to be opened.
I wondered why there is no constructor accepting a const string& parameter,
which forces the user to convert any filename to an old C-style string
before passing it to the constructor. Is this simply a historical legacy or
is there some deeper problem, which I might fail to see. Probably somebody
could shed some light on this issue.

Thanks
Chris
 
P

Pete Becker

Chris said:
as stated by the standard the fstream derivatives (ifstream & ofstream)
expect a const char*
parameter indicating the file name associated with the stream to be opened.
I wondered why there is no constructor accepting a const string& parameter,
which forces the user to convert any filename to an old C-style string
before passing it to the constructor. Is this simply a historical legacy or
is there some deeper problem, which I might fail to see. Probably somebody
could shed some light on this issue.

There are seventeen functions in the C++ standard that take const char*
but don't have analogs that take strings. Versions taking strings will
probably be added in the next standard.
 
C

Chris Theis

Pete Becker said:
There are seventeen functions in the C++ standard that take const char*
but don't have analogs that take strings. Versions taking strings will
probably be added in the next standard.

Thanks Pete for confirming what I had already expected. I just had expected
that the revision of the standard in 2003 would/could have introduced this,
but naturally there are certainly more important things to cover.

Cheers
Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top