Thread: Saving

  1. #1
    RPG'er
    Guest

    Saving

    Hi,
    My friend and I have only had a couple intro to programming classes. In our spare time, we managed to put together a massive (16,000 lines of code, but mostly simple if's and rnd's) character generator program for our role-playing game, though it is not Windows but only console.

    We got the program to be able to create a .txt file and save it, allowing users to print out the info later, which is a REAL accomplishment for us. We have one question: how can we get it to allow the user to enter their own name for the file?

    Here is what we have now:

    // code-on

    ofstream outfile;
    outfile.open("filename.txt");

    // code-off

    Is there a limit to filename length, or do we have to determine it? Thank you.

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    You can do something like this...

    Note: You must use

    #include <string>
    using namespace std;

    Code:
    string szFileName;
    
    cout << "Please enter a filename: ";
    getline( cin, szFileName );
    
    ofstream fout( szFilename.c_str() );
    
    // More usefull stuff
    
    fout.close( );
    Something like that should work fine.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. New to C++ problem saving files
    By wesm in forum C++ Programming
    Replies: 2
    Last Post: 11-02-2005, 02:00 PM
  2. Replies: 2
    Last Post: 06-16-2005, 10:03 AM
  3. saving a binary tree??
    By fayte in forum C++ Programming
    Replies: 9
    Last Post: 01-27-2005, 01:32 PM
  4. Saving vectors of structures problem
    By redeck in forum C++ Programming
    Replies: 4
    Last Post: 12-09-2004, 04:47 PM
  5. File saving problem in DevC++ pls help ???
    By intruder in forum C Programming
    Replies: 3
    Last Post: 12-17-2002, 01:17 AM