CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Stream types

  1. #1
    Join Date
    Jan 2006
    Posts
    344

    Stream types

    Is it possible to get the filename from a stream?

    My class has access to a ofstream that another class creates but I need to create an ifstream that has access to that file also. To pass the filename to the class it would mean modifying half a dozen classes just to pass the filename. I was hoping I wouldn't have to do that, but can't see a way looking at the fstream header of initializing from another stream or retrieving the original filename.

    G.

  2. #2
    Join Date
    May 2007
    Location
    Scotland
    Posts
    1,164

    Re: Stream types

    I don't know of any way to do this. That said, I must admit, where possible I wrap ofstream and ifstream objects in RAII classes, and give these classes the ability to return the filename that they have been initialised with. I don't know if this is possible in your situation but, if you are going to make a change to the interfaces anyway it might possibly be worth considering wrapping the ofstream object so that you don't have to pass multiple file related objects at each interface? There is also the increased exception saftey of a properly implemented RAII wrapper.

  3. #3
    Join Date
    Jan 2006
    Posts
    344

    Re: Stream types

    I had considered wrapping it in a class but thought it was a bit overkill just to get the filename back. I hadn't planned on doing anything else with it.

    Probably will go with that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured