Q:

Use cin.clear() or cin,ignore() for ONLY previous line input?

Is there a way to use cin.clear() or cin,ignore() for ONLY the previous line of input without clearing ALL previous input? For example in my code I prompt the user for input for each month, well if the input is less than 0 I would like the program to clear that negative input so that it does not get total into my calculation. Problem is it clears ALL previous input which still screws up the calculation. Thanks for any ideas in advance.
// prompt user for input, keep a total sum of data entered
    for(int i = 0; i < 12; i++)
    {
        cout << "Enter total rainfall for " << year[i] << endl;
        cin >> month[i];
        total += month[i];

    while(month[i] < 0)
    {
        cout << "Ony enter positive numeric values!" << endl;
        cin.clear();
            cin >> month[i];

    }   

    }

A:

You seem to be mixing up two distinct issues.  ios_base::clear()
doesn't remove any input; it resets the error status of the stream.
istream::ignore( n, ch ), on the other hand, reads forward until n
characters have been extracted or a character ch is seen'
myInput.ignore( INT_MAX, '\n' ) should ignore everything up to (and
including) the next '\n'. 
but your code has one thing that is very strange:
cin << month[i];

You can't output to std::cin.

A:

You probably want something like this:
unsigned int month[12];

for(size_t i = 0; i < 12; i++)
{
    cout << "Enter total rainfall for month " << i+1 << endl;
    while (!(cin >> month[i]))
    {
        cout << "Invalid input, try again." << endl;
        cin.clear();
        cin.ignore(numeric_limits<streamsize>::max(), '\n');    
    }
    // you probably want to repeat ignore() stuff here
    // so in case user inputs something like 10x, the "x" that was left
    // in the stream gets discarded
}

Note the array of unsigned integers. This way input like "-5" is automatically considered invalid so you don't need the less than 0 check. Clearing the entire stream shuouldn't worry you - if the input operation succeeds, the relevant part is already stored in your array.

