2013-09-16, 07:24 AM
The lines you marked as wrong are wrong on two counts.
- The first is that they mix output and input: you want to display the prompt (output), and read the file name that the user types in (input).
- The second is that you are trying to input "inF" and "outF" directly. Yet you already know that you open a file by its name in string form. You currently have
You even have, in your new code, open(???). So, you know you need to use that method.
What you want to do is replace the constant string by a variable that you get from the user.
To fix both counts we create code like this:
On a side-note, sleep.
I guarantee that programming is much easier when you're not exhausted.
- The first is that they mix output and input: you want to display the prompt (output), and read the file name that the user types in (input).
- The second is that you are trying to input "inF" and "outF" directly. Yet you already know that you open a file by its name in string form. You currently have
Code:
inF.open("numbersIn.txt");What you want to do is replace the constant string by a variable that you get from the user.
To fix both counts we create code like this:
Code:
string inputFileName;
cout << "Enter input file name: " ; // Show prompt. Note no endl, that keeps the cursor on the same line
cin >> inputFileName; // Get file name
inF.open(inputFileName); // Attempt to open a file by that name.
if (inF.fail())
// etc etc as before
// same block for outFOn a side-note, sleep.
I guarantee that programming is much easier when you're not exhausted.

