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;
}
Member Avatar for iamthwee

Are you trying to output the lines?

your program is not reading anything so fin.eof() never happens.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.