End of File

I'm trying to write a program that reads from a data file.
And when I put the while(!inFile.eof()) it created an endless loop. How would I fix this?
Upload the code and we'll see what's going on.
#include <iostream>
#include <string>
#include <fstream>




using namespace std;

int main()
{
string calc;
int test;
int cool;
int book;
ifstream myfile;
ifstream outof;
myfile.open ("program.txt");
outof.open("program.txt");
if (myfile.fail())
{
cerr<<"Error Opening file"<<endl;








}

if(outof.fail ())
{
cerr<<"Error Opening file"<<endl;


}
while (!myfile.eof ())
{
getline(myfile,calc);

}
cout <<calc<<endl;
while (!outof.eof ())
{
outof<<test;// Problem Here<----


cool++;
}
cout<<cool<<endl;
myfile.close();
outof.close();
}

im trying to print out integer values and number of lines but I cant seem to do it. the last part it says no match for operator also I tried exit (1) after the cerr, its not working saying exit was not defined.
1
35
45
87

9

100
^^This is the file I made program.txt( its in the code blocks folder)
This code was written by help of a friend too. I am a complete noob to this!
If you guys can give some input would be helpful
and this is my first post YAY!
Last edited on
Topic archived. No new replies allowed.