changin output file name

This is a discussion on changin output file name within the C++ Programming forums, part of the General Programming Boards category; I'm trying to write a program for class (yes, I'm just learning programming ) and I need to get a ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    2

    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.

    Matt

  2. #2
    Unregistered
    Guest
    ofstream fout;
    char filename[80];
    char more = 'y';
    while(more == 'y')
    {
    cout << "enter new file name with extents----xxxxx.eee" << endl;
    cin >> filename;
    fout(filename);
    fout << "ha ha" << endl;
    fout.close();
    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
    Posts
    2
    Thanks for the quick reply, appreciate your help (and yes, it worked, but you knew that already).

    Matt

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. archive format
    By Nor in forum A Brief History of Cprogramming.com
    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, 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