Posts

Showing posts with the label cin ignore

C++ 04: cin Functions

  1) cin.ignore() : The cin.ignore() function is used which is used to ignore or clear one or more characters from the input buffer. To get the idea about ignore() is working, we have to see one problem, and its solution is found using the ignore() function. The problem is like below. Sometimes we need to clear the unwanted buffer, so when next input is taken, it stores into the desired container, but not in the buffer of previous variable. For example, after entering into the cin statement, we need to input a character array or string. So we need to clear the input buffer, otherwise it will occupy the buffer of previous variable. By pressing the “Enter” key after the first input, as the buffer of previous variable has space to hold new data, the program skips the following input of container. Write a program to read Date of birth of a person and display it. # include <iostream> using namespace std ; main () {      int   D ,  M ,  Y ; ...