Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am trying to write a program that numbers the lines from a giventext file (whi

ID: 3611924 • Letter: I

Question

I am trying to write a program that numbers the lines from a giventext file (which is specified by the user) and outputs the textfile's lines with numbers onto the screen and also to another textfile (also specified by the user). Here is my code I have sofar:

#include <fstream>
#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
    ifstream in_stream;
    ofstream out_stream;
    char in_file_name[16], out_file_name[16],symbol, line;
    int count = 0;
   
   
    cout << "Please enter a filename to readfrom (max 15 characters): ";
    cin >> in_file_name;
   
    in_stream.open(in_file_name);
    if (in_stream.fail())
    {
       cout << "Input fileopening failed. ";
      
       system("pause");
       exit(1);
    }

    cout << "Pleaes enter a output filename(max 15 characters): ";
    cin >> out_file_name;
   
    out_stream.open(out_file_name);
    if (out_stream.fail())
    {
       cout << "Output fileopening failed. ";
      
       system("pause");
       exit(1);
    }
   
    do
    {
        if (symbol != ' ')
        {
          in_stream.get(symbol);
           line =symbol;
        }
        else
        {
          count++;
       
           cout<< count << ": " << symbol;
       
          out_stream << count << ": " << symbol;
        }
    } while (! in_stream.eof());
   
    //count++;
   
    //cout << count << ". " <<line << " ";
       
    //out_stream << count << ". "<< symbol;
   
   
    system("pause");
    return 0;
}

If someone could either help me with this or steer me in the rightdirection, I would appreciate it very much.

Explanation / Answer

please rate - thanks you should be reading a line at a time, not a character at atime #include #include #include using namespace std; int main() {     ifstream in_stream;     ofstream out_stream;     char in_file_name[16], out_file_name[16];     string line;     int count = 0;     cout > in_file_name;     in_stream.open(in_file_name);     if (in_stream.fail())     {        cout out_file_name;     out_stream.open(out_file_name);     if (out_stream.fail())     {        cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote