Taking a single character input in C++ is
#include <iostream> int main() { char input; std::cout << "Enter a single character: "; std::cin >> input; std::cout << "You entered: " << input << std::endl; return 0; }
Output:
Enter a single character:
a
You entered: a
In this code:
#include <iostream>
: This includes the input-output stream library.char input;
: Declares a variableinput
of typechar
to store the single character input.std::cout << "Enter a single character: ";
: Prompts the user to enter a character.std::cin >> input;
: Takes the single character input from the user.std::cout << "You entered: " << input << std::endl;
: Outputs the entered character.