strings & ofstream

This is a discussion on strings & ofstream within the C++ Programming forums, part of the General Programming Boards category; Code: string name; cin>>name; ofstream name_file ( name ); how would you do the above, as it obviously doesn't work....

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    29

    strings & ofstream

    Code:
    string name;
    cin>>name;
    ofstream name_file ( name );
    how would you do the above, as it obviously doesn't work.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    Code:
    ofstream name_file(name.c_str());
    It's an oversight in the standard that the file streams can't take std::strings for the file name. It will be fixed in the next revision of the standard.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strings Program
    By limergal in forum C++ Programming
    Replies: 4
    Last Post: 12-02-2006, 02:24 PM
  2. Programming using strings
    By jlu0418 in forum C++ Programming
    Replies: 5
    Last Post: 11-26-2006, 07:07 PM
  3. Ofstream, Ifstream, Searching files for strings?
    By Zeusbwr in forum C++ Programming
    Replies: 10
    Last Post: 04-04-2005, 03:45 PM
  4. Capturing key presses
    By cgod in forum Windows Programming
    Replies: 6
    Last Post: 11-25-2004, 12:10 PM
  5. Reading strings input by the user...
    By Cmuppet in forum C Programming
    Replies: 13
    Last Post: 07-21-2004, 06:37 AM

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