设置一个字节等于int和cout

Setting a byte equal to an int and cout

本文关键字:int cout 字节 一个 设置      更新时间:2023-10-16

所以我理解c++将字节定义为类型定义的unsigned char。但我不能完全理解为什么,在将字节变量设置为int后,它被视为笑脸…

#include <iostream>
#include <Windows.h>
using namespace std;
int main(){
    int x = 1;
    byte y = x;
    cout << y;
}
我相信这有一个简单的解释,但我似乎找不到它。unicode或UTF8的第一个字符是否设置为笑脸?

您一定是在使用Windows。代码为1的字符是code Page 437中的笑脸,命令窗口使用的笑脸。代码点031不对应Unicode中的可打印字符。

是的,byte通常定义为unsigned char。当您将char变量(有符号或无符号)发送给cout时,它输出一个字符而不是一个数字。