Which C++ input stream function examines the next character without extracting it from the stream?

Options

  • A. peek()
  • B. ignore()
  • C. clear()
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

A. peek()

Detailed Explanation

Answer: (A) peek()

The peek() function examines the next character in the input stream without removing it from the stream.

For example:

char ch = cin.peek();

The next available character is examined and can be stored in ch, while the character remains available in the input stream.

This is useful when a program needs to check the next input character before deciding what operation to perform.