输入a b
输出为什么会有一个10
结尾呢?
输出为:
97
a
32
98
b
10
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
int chr;
while ((chr = getchar()) != EOF)
{
cout<<chr<<endl;
if (char(chr))
{
cout<<char(chr)<<endl;
}
}
return 0;
}
When you enter 97 and then retract, you actually entered three characters: 9, 7, newline, so the following output will appear:
97
57 -> ASCII code of the number 9
9 -> Number 9 character
55 -> Number 7 ASCII code
7 -> Number 7 character
10 -> Line break ASCII code
-> Here is a Line break
Generally, you need to add a get() to remove the newline character