I have an infintie loop an i don't know why

need help finding out cause of infinite loop

Page 1 of 1

1 Replies - 984 Views - Last Post: 30 November 2008 - 04:36 PM Rate Topic: -----

#1 Zerobu   User is offline

  • Black Hatter

Reputation: 13
  • View blog
  • Posts: 1,822
  • Joined: 14-January 08

I have an infintie loop an i don't know why

Post icon  Posted 30 November 2008 - 04:17 PM

I need help finding out the cause of this infinite loop. It happens in the while loop when i try to test if the file is at the end of file.

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



void PrintCriminal(ofstream & fout, string line)
{
	string name;


	fout<<"<p><hr>";

	

	


}

void main()
{

	ofstream fout;
	ifstream fin;
	string line;

	fout.open("wanted.html");
	fin.open("criminals.txt");

	fout<<"<h1>Wanted</h1>";

	while( !fin.eof())
	{

		getline(fin, line);

		PrintCriminal(fout, line);

	}

	fout.close();
	fin.close();
}

	




Is This A Good Question/Topic? 0
  • +

Replies To: I have an infintie loop an i don't know why

#2 janotte   User is offline

  • code > sword
  • member icon

Reputation: 991
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: I have an infintie loop an i don't know why

Posted 30 November 2008 - 04:36 PM

Have a look here for an alternate approach to eof() that might be of interest.
http://mathbits.com/...i/Files/End.htm
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1