how can i get the ofstream file name

This is a discussion on how can i get the ofstream file name within the C++ Programming forums, part of the General Programming Boards category; Hello all it seams to be beginners question , but do i have the possibility to get the file name ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    58

    how can i get the ofstream file name

    Hello all
    it seams to be beginners question , but do i have the possibility to get the
    file name i set in the ofstream constructor?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,258
    Considering that you set it, obviously you know it, so you just need to save it.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    58
    i meant ou tof the ofstream variable
    if i have
    ofstream file("foo.txt")
    how can i get from file variable the "foo.txt" string

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,258
    Quote Originally Posted by umen242
    how can i get from file variable the "foo.txt" string
    You cannot do that.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by laserlight View Post
    You cannot do that.
    You could of course define your own class that stores the name of the file before opening an ofstream, and then make a ofstream cast-operator that returns the actual ofstream.

    But there is absolutely no standard way to get the filename out of a stream, and I know of no implementation of file-streams that actually store the filename as part of the stream object.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File Writing Problem
    By polskash in forum C Programming
    Replies: 3
    Last Post: 02-13-2009, 10:47 AM
  2. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 08:51 PM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 09:39 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21