- Feb 15, 2003
- 693
- 0
- 0
Hello,
I am writing a program for my c++ course and am having a problem.
I am creating my own string class, it is call String150. The loop for my getline function looks like this:
while(!fileIn.eof() && ch != '\n' ) //checks for end of file and new line
{
str150 = str150 + ch; //concats a char at a time
fileIn.get(ch);
}
there is a fileIn.get(ch) above the loop as well, just a standard Sentinal controlled loop.
My problem is this. getline will get the line without any problems but when I am returned to main, my loop that is counting the words also tests for EOF, it then skips the loop I need to go into to process the last line. I can change main becuase that was a homework assignment from a while ago, and the String150 class is meant to be a drop in replacement for the standard string class. Any hints would be great. I have looked at the putback function but am unsure if thats what I need to use or even how to implement it.
I am writing a program for my c++ course and am having a problem.
I am creating my own string class, it is call String150. The loop for my getline function looks like this:
while(!fileIn.eof() && ch != '\n' ) //checks for end of file and new line
{
str150 = str150 + ch; //concats a char at a time
fileIn.get(ch);
}
there is a fileIn.get(ch) above the loop as well, just a standard Sentinal controlled loop.
My problem is this. getline will get the line without any problems but when I am returned to main, my loop that is counting the words also tests for EOF, it then skips the loop I need to go into to process the last line. I can change main becuase that was a homework assignment from a while ago, and the String150 class is meant to be a drop in replacement for the standard string class. Any hints would be great. I have looked at the putback function but am unsure if thats what I need to use or even how to implement it.