While(!fin.eof ()) Loop not ending

Hi everyone, I am new to coding, and I can't find any useful infomation to help me with my problem, so I was wondering if someone here could help me.
I have this code, and the while(!fin.eof ()) loop is not ending.

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

void read (ifstream & infile,const char fileName[200]);

int main()
{

char fileName [200]; // file Name
ifstream infile(fileName); // declare input file stream
char lineOutput [200];
ifstream fin;

cout << "please enter your file name: "<< endl;
cin.getline (fileName, sizeof(fileName));

cout << "FILENAME: "<< fileName << "\n" <<endl;

infile.open (fileName); //open file


cout << "Contens FILE: " << fileName << ".txt are as follows::" <<endl;

while(!fin.eof ())
{
infile.getline (lineOutput, sizeof(lineOutput), '\n'); // get the first line from the file.
cout << lineOutput <<endl;
}

infile.close (); //close file

return 0;

}
Last edited on
You never opened a file in fin, rather in infile. Try changing/removing fin.
!infile.eof()
Last edited on
You are the best!!! thank you soooooooo much!!!!
Topic archived. No new replies allowed.