samedi 29 août 2015

c++ - Understanding what exactly this code does [duplicate]

This question already has an answer here:

I have the following snippet:

    cin.ignore(numeric_limits<streamsize>::max(), '\n');

I am trying to understand precisely what it does, as I cannot figure it out... here it is in context:

while (!(cin >> originalPrice)) {
            cin.clear();
            cin.ignore(numeric_limits<streamsize>::max(), '\n');
            cout << "That wasn't good input!\nEnter the original price of the item you are buying: (ex. 5.45):";
                        }

I think it prevents us from capturing the carriage return, but I am a C++ noob and am lost.

Aucun commentaire:

Enregistrer un commentaire