Dec 13, 2014 at 5:28am UTC  
 
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 Dec 13, 2014 at 5:28am UTC  
 
 
 
 
  Dec 13, 2014 at 6:16am UTC  
 
You never opened a file in fin, rather in infile. Try changing/removing fin.
 
Last edited on Dec 13, 2014 at 6:16am UTC  
 
 
 
 
  Dec 13, 2014 at 11:32am UTC  
 
You are the best!!! thank you soooooooo much!!!!