Q:

c++ Why does a .ignore() function not work properly?

A list of Numbers go to the Stack if the number is greater then 0 and less than 50. A number goes to the queue if the number is greater than 50 and less than 100. If the data is not a number, I want to discard it and go to the next read. This is where I am getting some problems.
Here is the while loop I am using to process the file of numbers:
while (infile)
{
    infile >> number; //takes in a number
    if (0 < number && number < 50)
    {
        PushToStack(number); // pushed to stack
    }
    else if (50 < number && number < 100)
    {
        PushToQueue(number); // pushes to queue
    }
    else
    {
        // discard and move to next read
        infile.ignore(1, '\n');
    }
}

I have tested this code a few times now and I have produced the following output:
Pushed To Stack: 12
Pushed To Stack: 44
Pushed To Stack: 23
Pushed To Queue: 55
Pushed To Queue: 55

As soon as a letter (lets say n for example) is included in the set, it does not continue reading the other numbers and it also repeats the last number. I thought infile.ignore(1,'\n') would skip to the next line. According to the c++ documentation, .ignore should skip to the next line. I assume I am using the ignore function incorrectly. Or is there be a better way, without using .ignore to skip any bad data included and continue reading in numbers from a file like this?

A:

infile.ignore(1, '\n') will ignore at most one character. 
try this instead:
infile.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
this will ignore as many characters as the architecture can count, but will stop ignoring after encountering a newline or end of file.
std::numeric_limits is defined in <limits>

