c/c++ 字符转换
PHP中文网
PHP中文网 2017-04-17 15:07:53
0
2
614

输入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;
}
PHP中文网
PHP中文网

认证0级讲师

reply all(2)
Peter_Zhu

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!