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

I cannot get this to compile: #include<iostream> #include<fstream> #include<stri

ID: 3646870 • Letter: I

Question

I cannot get this to compile:

#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
using namespace std;

int main()
{
string filename;
char line [120];
fstream fin;
cout<<"Enter a file name "<<endl;
cin >>filename;
fin.open (filename, ios ::in);
if(!fin)
{
cout<<"Error in file opening"<<endl;
}
else
{
int counter =0;
while (!fin.eof())
{
if (counter > 25)
{
getch();
counter = 0;
}
fin.getline(line, 121, ' ');
cout<<line<<endl;
counter++;
}
}
system ("pause");
return 0;
}
//end main

Explanation / Answer

please rate - thanks

#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
using namespace std;

int main()
{
//string filename;
    char filename[80];    //needs to be char array
char line [120];
fstream fin;
cout<<"Enter a file name "<<endl;
cin >>filename;
fin.open (filename, ios ::in);
if(!fin)
{
cout<<"Error in file opening"<<endl;
}
else
{
int counter =0;
while (!fin.eof())
{
if (counter > 25)
{//getch();            need to include conio.h to use this, system("pause") better since gives the prompt
system("pause");  
counter = 0;
}
fin.getline(line, 121, ' ');
cout<<line<<endl;
counter++;
}
}
system ("pause");
return 0;
}
//end main

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