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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.