Help with File I/O

This is a discussion on Help with File I/O within the C++ Programming forums, part of the General Programming Boards category; Is it possible to some how take a file name from cin and use that to open the file? EXAMPLE: ...

  1. #1
    Registered User MoonMan's Avatar
    Join Date
    Nov 2011
    Posts
    19

    Red face Help with File I/O

    Is it possible to some how take a file name from cin and use that to open the file?

    EXAMPLE:
    Code:
    int main() 
    {
      string filename;
      cout << "Please enter the file name to open: ";   
      cin >> filename;   
      ofstream a_file ( **HOW TO CALL IT HERE?** );  
    }
    Sorry if this question is silly, I am still learning!

    Thank you much

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,303
    Like this:
    Code:
    ofstream a_file(filename.c_str());
    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 MoonMan's Avatar
    Join Date
    Nov 2011
    Posts
    19
    Thank you very much!

    best regards

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 09-25-2011, 01:22 AM
  2. Replies: 3
    Last Post: 03-08-2010, 02:43 PM
  3. Replies: 2
    Last Post: 03-04-2010, 04:19 AM
  4. Replies: 3
    Last Post: 11-21-2006, 07:26 PM
  5. Replies: 4
    Last Post: 07-06-2006, 03:53 AM

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