Why does character input display a complete string if a string is entered?
Here's a simple code
1 2 3 4 5 6 7 8 9 10 11
|
#include <iostream>
using namespace std;
int main()
{
char c;
cin >> c;
cout << c;
return 0;
}
|
If I enter, "HHH" in this.. It will display "HHH" as well. Why?
Shouldn't a character be reading a single character at a time?
Also, how do I check if the user has entered a single character or more than one character in a character variable (without using string variable)
You have a funny compiler!
It output just
H
for me.
I am using Visual Studio 2019.
Like I said. You have a funny compiler.
I used VS 2019 and I get only one character for the output from your source code. Same as lastchance.
Your copy of VS 2019 might be buggy, in need of repair.
Also, how do I check if the user has entered a single character or more than one character in a character variable (without using string variable)
|
If you enter HHH it will display
as expected. The first HHH line is what is echoed when input. The H line is what is displayed by the cout.
Topic archived. No new replies allowed.