0

I'm just trying to scroll through a input file, fin is the object name and it goes into an infinite loop. I'm using this check
!fin.eof what am I missing or not understanding?

#include <iostream>
#include <fstream>
#include <cctype>
#include <cstdlib>
#include <string>

using namespace std;

// ------ PROTOTYPES ---------------------------------------------

// ****** MAIN ***************************************************
int main()
{
    char over[] = " over ";
    char to[] = " to ";

    cout << over;
    string fName = "iFile.txt";
    ifstream fin(fName.c_str());
    char buffer[80];

    if(!fin)
    {
        cerr << "\nCouldn't open " << fName;
        exit(1);
    }

    while(!fin.eof())
    {
        cout << over[0];
    }


    return 0;
}
4
Contributors
3
Replies
26
Views
3 Years
Discussion Span
Last Post by jamesjvj
0

Your program will never reach the end of the file if it doesn't move the file cursor to it. You can do it for example by reading every line of the file. Also, don't forget to close your file with "fin.close();" after everything is done.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.