some one help wiht output file

This is a discussion on some one help wiht output file within the C++ Programming forums, part of the General Programming Boards category; how do i change the output file according to the input from the user? Ex: user enter "test" how do ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    1

    some one help wiht output file

    how do i change the output file according to the input from the user?
    Ex:
    user enter "test"
    how do i make the rest of the program to be out puted to test.txt
    or if he entered "exam"
    to exam.txt
    and so on.

  2. #2
    Registered User Engineer's Avatar
    Join Date
    Oct 2001
    Posts
    125
    if i understand the question correctly, you want to scan the user's input, and then create and open the file using the input you just scanned.

    so the logic of your program should ask the user for the file name, check if the name entered is valid and can be used, open a file with this name and work with this file. so based on what name the user is going to enter, your program will create the file with a appropriate name.
    1 rule of the Samurai Code: if you have nothing to say, don't say anything at all!

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    2

    Post Trouble with File Output

    I had a similiar problem. I made a RPG, and I have the username as the filename and the password as the first line of the file. The other lines are experience counters. I can add the exp at any time. I had to use a struct for all the variables. Use a unique filename for each you say? Anyways I hope this helps.....



    FloYd

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,788
    This worked for me using MSVC++ 6.0:
    Code:
    #include <fstream>
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main()
    {
        cout << "Type in filename: ";
        string strFName;
        cin >> strFName;
        strFName += ".Txt";
        cout << "Creating output file: " << strFName << endl;
        ofstream OutputFile( strFName.c_str() );
    
        return 0;
    }
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Base converter libary
    By cdonlan in forum C++ Programming
    Replies: 22
    Last Post: 05-15-2005, 01:11 AM
  2. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  3. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM
  4. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 02:58 PM
  5. Simple File Creation Algorithm
    By muffin in forum C Programming
    Replies: 13
    Last Post: 08-24-2001, 03:28 PM

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