Question: I have recently been introduced to the Velocity project.

I have written a template and have run it as a simple Java application.

Integration within my existing web project has not been that easy.

Can anyone supply a cookbook for integrating Velocity and Tomcat?

Thanks all!

Answer: 
Presuming `iFile` is an `istream`: 

You should break out of the loop on *any* error, not only on EOF (which can be checked for with `iFile.eof()`, BTW), because this is an endless loop when any format failure sets the stream into a bad state other that EOF. It is usually necessary to break out of a reading loop in the middle of the loop, after everything was read (either successfully or not), and before it is entered. 

To make sure there isn't anything interesting coming anymore, you could, after the loop, reset the stream state and then try to read whitespace only until your reach EOF: 

```
while( !iFile.eof() )
{
   iFile >> std::ws;
   string line;
   std::getline(iFile,line);
   if(!line.empty()) error(...);
}

```
EOF is not a prediction but an error state. Hence, you can't use it like you're using it now, to predict whether you can read Column 1, 2 and 3. For that reason, a common pattern in C++ is:

```
while (input >> obj1 >> obj2) {
  use(obj1, obj2);
}

```

All `operator>>(istream& is, T&)` return the inputstream, and when used in boolean context the stream is "true" as long as the last extraction succeeded. It's then safe to use the extracted objects.