阅读 45

c语言a>b>c,char型转换成int

基于这个C 11计划,应该期待数字还是字母吗? 还是不期待?

#包含

#包含

int main () )

{

int8_t i=65;

std:cout i;

}

标准指定此类型为字符类型吗?

解决方法:

根据c0xFDIS(n3290 )的18.4.1[cstdint.syn],int8_t是可选的typedef,其规范如下:

namespace std {

typedef signed integer type int8_t;//选项

//.

} //namespace std

3.9.1 [ basic.fundamental ] tzdz xc :

therearefivestandardsignedintegertypes : " signed char "、" short int "、" int "、" long int "、 and“longlong int”. int hing eachtypeprovidesatleastasmuchstorageasthoseprecedingitinthelist.theremayalsobeimplementation-tion thestandardandextendedsignedintegertypesarecollectivelycalledsignedintegertypes。

.

Types bool,char,char16_t,char32_t,wchar_t,andthesignedandunsignedintegertypesarecollectivelycalledintegraltegraltytivegraltettegraltyttted

3.9.1还规定:

In any particular implementation,aplaincharobjectcantakeoneitherthesamevaluesasignedcharoranunsignedchar; 定义-隐藏。

int8_t可以得出结论,假设char对象采用有符号的值,它很可能是char的typedef,但不是,因为char不在有符号整数类型的列表中。 标准和可扩展的有符号整数类型。 另请参阅std : make_unsigned和std : make_signed中的stephant.lava vej’s Cooke

因此,int8_t是signed char的typedef,或扩展的有符号整数类型,该对象正好占用8位存储区。

但是,要回答你的问题,不应该假设。因为已经定义了x.operator

模板class traits basic_ostreamLT炭,性状GT安培; 如果int8_t是签名字符的完全匹配,即signed char的typedef,则调用操作符,signed char模板。

否则,int8_t将升级为int和basic_ostream charT,traits将调用操作器

在std : cout上

模板class traits basic_ostreamLT炭,性状GT安培; 如果uint8_t与unsigned char完全匹配,则调用操作者,unsigned char模板。

否则,uint8_t将升级为int和basic_ostream charT,traits将调用操作器,因为int可以表示所有uint8_t值

如果您总是想打印角色,最安全、最明确的选择是:

STD:3360coutstatic_cast(I;

如果你想一直印数字:

STD:3360coutstatic_cast(I;

标签: c,c11,语言层,iostream,标准库

资料来源: https://codeday.me/bug/2019 09 23/1813451.html


文章分类
代码人生
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐