Thread: Have the User Name a File

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    12

    Have the User Name a File

    I am using fstream.h, and I want the user to be able to name the file. But it is in a string literal? and I don't know how I can have them name it? Is this possible?

    JDM

  2. #2
    Rabite SirCrono6's Avatar
    Join Date
    Nov 2003
    Location
    California, US
    Posts
    269
    Yes, it is possible.

    Code:
    #include <iostream>
    #include <fstream>
    #include <string>
    
    int main( void )
    {
      std::string Name;
      std::cout << "What is the file name? " << std::endl;
      std::getline( std::cin, Name );
      std::ofstream fOut( Name.c_str() );
      fOut << //Put in stuff
      fOut.close();
      return 0;
    }
    There you go.

    - SirCrono6
    From C to shining C++!

    Great graphics, sounds, algorithms, AI, pathfinding, visual effects, cutscenes, etc., etc. do NOT make a good game.
    - Bubba

    IDE and Compiler - Code::Blocks with MinGW
    Operating System - Windows XP Professional x64 Edition

  3. #3
    Registered User
    Join Date
    Dec 2003
    Posts
    12
    Thank you very much!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM
  4. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM