Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating and implementing functions (C++).
#16
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
Code:
inF.open("numbersIn.txt");
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:
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 outF

On a side-note, sleep.
I guarantee that programming is much easier when you're not exhausted.
Reply


Messages In This Thread
Creating and implementing functions (C++). - by SaptaZapta - 2013-09-16, 07:24 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)