Thread: fstream question

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    2

    fstream question

    hi everyone

    I was woundering if it was possible to have fstream open a variable filename like instead of having to tell it the name have the name of the file x.txt so it opens any txt file, or have the user define the filename. its kinda hard to explain but ive been woundering this for a while now.

    thanks in advance

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Certainly. Just use a variable name for the file name, and set the file name before calling open.
    Mainframe assembler programmer by trade. C coder when I can.

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    2
    could you show me an example, im still kinda stuck.

  4. #4
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Code:
    std::string filename( "blah.txt" );
    std::fstream file( filename.c_str() );

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 12:14 PM
  2. FStream Question
    By CPP-Null in forum C++ Programming
    Replies: 5
    Last Post: 05-25-2003, 01:28 PM
  3. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  4. fstream question!
    By FutureCoder in forum C++ Programming
    Replies: 1
    Last Post: 01-31-2003, 04:06 PM
  5. Problems with fstreams.
    By mosdef in forum C++ Programming
    Replies: 7
    Last Post: 06-19-2002, 03:36 PM