fstream question

This is a discussion on fstream question within the C++ Programming forums, part of the General Programming Boards category; hi everyone I was woundering if it was possible to have fstream open a variable filename like instead of having ...

  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
    Katy, Texas
    Posts
    2,309
    Certainly. Just use a variable name for the file name, and set the file name before calling open.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  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, 01:14 PM
  2. FStream Question
    By CPP-Null in forum C++ Programming
    Replies: 5
    Last Post: 05-25-2003, 02: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, 04:36 PM

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