Which C++ stream function can be used to extract and discard characters from the input stream?
Options
- A. ignore()
- B. display()
- C. print()
- D. More than one of the above
- E. None of the above
Quiz Practice:
A. ignore()
Answer: (A) ignore()
The ignore() function of the input stream can be used to extract and discard characters from the input buffer.
For example:
cin.ignore(100, '
');
This can discard characters until the specified limit is reached or the newline character is encountered.
It is frequently useful when unwanted characters remain in the input stream after formatted input.