Thread: changin output file name

  1. #1
    Registered User
    Join Date
    Feb 2002

    changin output file name

    I'm trying to write a program for class (yes, I'm just learning programming) and I need to get a string input, then produce an output text file with that name. I know how to write output to text files, but I can't figure out how I can get the value of a string variable to be the name of the text file, therefore producing a new file each time a new name is entered. The problem for me is the fact that the filename is in double quotes "example.txt", so I can't substitute the variable name in. Any help is appreciated. Thanks.


  2. #2
    ofstream fout;
    char filename[80];
    char more = 'y';
    while(more == 'y')
    cout << "enter new file name with extents----xxxxx.eee" << endl;
    cin >> filename;
    fout << "ha ha" << endl;
    cout << "more? y/n)
    cin >> more;

    the parameter for streams is a c_style string or object that can be converted into c_style string "automatically" like a literal string (string in double quotes) or instance of string class from STL.

  3. #3
    Registered User
    Join Date
    Feb 2002
    Thanks for the quick reply, appreciate your help (and yes, it worked, but you knew that already).


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. archive format
    By Nor in forum A Brief History of
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM
  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, 03:58 PM
  5. Simple File Creation Algorithm
    By muffin in forum C Programming
    Replies: 13
    Last Post: 08-24-2001, 03:28 PM