DEV Community

Emmanuel Nyarko
Emmanuel Nyarko

Posted on

Input streams buffer flag clearing and emptying

The input streams works in such as a way that it holds some particular type of when undisturbed. Particularly with C++,when you try to extract a string and an integer continuously as in getting a name and age attributes of a person together for instance, the stream doesn't react to this sudden change of type data. To be able to adjust this change of memory, you have to employ the cin.ignore() object to be able to release the buffer of the integer and open a new room for the string to be extracted. And sometimes when you incorrectly place the wrong data type into the allocated buffer, flags are raised to tell you that you've committed error. Cin.clear() is used to clear the flags so that the buffer will ignore the error you committed. The buffer will now pretend that you entered the corrected data type and allow you carry on. You can cin.ignore() to remove the incorrect entry and manipulatively allow you re-enter the right value(data type) .
We will implement more on input streams

Top comments (0)