What does this cin.clear() and cin.ignore() means?

this is the part of the code :

while(1) { 
      cout<<"Enter the Product ID :";
      cin>>product[i].id;
      cout<<endl;
      
      if(cin.fail())
        {
                      cout << "\t\t\t\t\WRONG ID DATA!" << endl;
                      cin.clear(); //what does it means??
                      cin.ignore(1000, '\n'); //why 1000??
                      continue;
        }
        break;
}

thank you for helping....

Clear clears the failbit (a flag (bit) that was set to true when your used typed in a letter for your id instead of a number). cin.fail() is what checks the bits to see if the failbit has been set and returns true if it was. At that time that it fails, the stream is no longer valid to take more input. Clear allows you to reset this failed state and once again take input into your stream.
http://www.cplusplus.com/reference/iostream/ios/clear/

Ignore in that case discards up to 1000 characters or until it reaches a newline (whichever comes first).
http://www.cplusplus.com/reference/iostream/istream/ignore/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.