fstream constructor

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

    #1

    fstream constructor

    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


  • Pete Becker

    #2
    Re: fstream constructor

    Chris Theis wrote:[color=blue]
    >
    > 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.
    >[/color]

    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.

    --

    Pete Becker
    Dinkumware, Ltd. (http://www.dinkumware.com)

    Comment

    • Chris Theis

      #3
      Re: fstream constructor

      "Pete Becker" <petebecker@acm .org> wrote in message
      news:qqSdnUOTof snlhbenZ2dnUVZ_ sCdnZ2d@rcn.net ...[color=blue]
      > Chris Theis wrote:[color=green]
      >>
      >> 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.
      >>[/color]
      >
      > 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.
      >[/color]

      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


      Comment

      Working...