// Description: Illustrate the use of cin khổng lồ get input// & how to lớn recover from errors.#include using namespace std;int main(){ int input_var = 0; // Enter the vì while loop & stay there until either // a non-numeric is entered, or -1 is entered. Lưu ý that // cin will accept any integer, 4, 40, 400, etc. Vì chưng { cout > input_var)) { cout What is the significance of cin.clear() & cin.ignore()? Why are the 10000 and parameters necessary?

c++ đầu vào iostream cin mô tả Improve this question Follow edited Apr 3 “20 at 12:24


flightflight 6,75344 gold badges2222 silver badges3030 bronze badges 1 add a comment | 28Why do we use:

1) cin.ignore

2) cin.clear



1) khổng lồ ignore (extract và discard) values that we don”t want on the stream

2) to lớn clear the internal state of stream. After using cin.clear internal state is set again back lớn goodbit, which means that there are no “errors”.

Long version:

If something is put on “stream” (cin) then it must be taken from there. By “taken” we mean “used”, “removed”, “extracted” from stream. Stream has a flow.

Bạn đang xem: Cin.ignore là gì

Xem thêm: 130 Câu Trắc Nghiệm Tin Học Văn Phòng Và Đáp Án – Phần 1, 130 Câu Trắc Nghiệm Tin Học Văn Phòng Và Đáp Án

The data is flowing on cin like water on stream. You simply cannot stop the flow of water