首页
|
编程语言
|
网站建设
|
游戏天堂
|
冲浪宝典
|
网络安全
|
操作系统
|
软件时空
|
硬件指南
|
病毒相关
|
IT 认证
软讯网络
>
编程语言
>
C/C++
> 输出字符'A'/'a'的解析
【标 题】:输出字符'A'/'a'的解析
【关键字】:
【来 源】:http://www.cppblog.com/zerolee/archive/2007/01/15/17631.html
输出字符'A'/'a'的解析
C++博客 - 一步一个脚印,走在自己前面! - 输出字符'A'/'a'的解析
一步一个脚印,走在自己前面!
走投无路? 逼自己上梁山吧!
C++博客
联系
聚合
管理
25 Posts :: 6 Stories :: 4 Comments :: 0 Trackbacks
留言簿
给我留言
查看公开留言
查看私人留言
随笔分类
C++ Performance (7)
Computer Graphics and Its Algorithm (2)
Experience and Thought (10)
Game development using C++ (0)
Software development using C++ (6)
随笔档案
2007年1月 (3)
2006年12月 (11)
2006年11月 (3)
2006年10月 (3)
2006年9月 (5)
文章档案
2006年10月 (2)
2006年9月 (4)
相册
经典黑白图片 (2)
经典美女展 (9)
汽车模型展 (5)
收藏夹
C++ Core Language (0)
C++ STL (0)
CG Bolg
badkeeper's CG Blog
Computer Graphics Blog -- zerolee
搜索
最新评论
1.?re: 将电脑和银行结合在一起,你会得到什么?
你这是从艾兰.库柏的书里摘来的吧。。。
--tonybain
2.?re: 建造原型的代价
[quote]面向对象技术只是将1000块砖分割成10组100块砖,不是根本的解决之道[/quote]
有理。
原型代码确实是为了扔掉而扔掉的。
--LOGOS
3.?re: 建造原型的代价
长见识了,叠砖论精辟!
--pengkuny
4.?re: 将电脑和银行结合在一起,你会得到什么?
同感
--pengkuny
阅读排行榜
1.?Problems about two functions of CImage in ATL(242)
2.?将电脑和银行结合在一起,你会得到什么?(190)
3.?精神病人管理着精神病院(185)
4.?建造原型的代价(149)
5.?C++高手必看的C++书单(98)
评论排行榜
1.?建造原型的代价(2)
2.?将电脑和银行结合在一起,你会得到什么?(2)
3.?从Coding Fan到真正的技术专家[转载](0)
4.?精神病人管理着精神病院(0)
5.?头文件中的名称(0)
输出字符'A'/'a'的解析
输出字符'A'/'a'的代码段:
?1????
//
?Test1:?Directly?insert?0x0A?and?0x41?to?ostream
?2
????cout?
<<
?
0x0A
;????
//
?print?type?int?10
?3
?4
????cout?
<<
?
'
?
'
;
?5
?6
????cout?
<<
?
0x41
;????
//
?print?type?int?65,?which?is?decimal?number?of?'A'.
?7
????cout?
<<
?
'
?
'
;
?8
?9
????
//
?Test2:?Directly?insert?'\x41'?to?ostream
10
????cout?
<<
?
'
\x41
'
;????
//
?'\x41'?is?transformed?char,?which?means?type?char?'A'.
11
??????????????????????
//
?So,?it?prints?type char 'A'? on screen.
12
????cout?
<<
?
'
?
'
;
13
14
????
//
?Test3:?First?assign?0x41?to?char?variable,?then?output?it.
15
????
char
?char_out?
=
?
0x41
;????
//
?char_out?is?equal?'A'?which?is?type?int?65.
16
????cout?
<<
?char_out;????????
//
?it?prints?type?char?'A'?on?screen.
17
18
????cout?
<<
?
'
?
'
;
19
????
//
?Test4:?First?cast?0x0A?to?char,?then?output?it.
20
????cout?
<<
?static_cast
<
char
>
(
0x41
); // it prints type char 'A' on screen.
21
????
22
????cout?
<<
?
'
?
'
;
23
????
//
?Test5:?Directly?insert?hexdecimal?type?number?of?'A'
24?
????cout?
<<
?std::hex
/*
<<?std::showbase
*/
?
<<
?
0x41
;?
//
?it?prints?string?literal?"41"?
25
????cout?
<<
?
'
?
'
?
<<
?std::hex?
<<
?
0x0A
;?
//
?it?prints?type?char 'a' on screen.
26
????
int
?int_out?
=
?
'
0x41
'
;
27
????cout?
<<
?int_out;?
//
?it?prints?type?int?8342**
28
29
????cout?
<<
?endl;
?? 0x41是字符'A'的16进制表示方式,它的10进制数是65,\x41是字符'A'的转义字符。而0x0A跟字符'A'没有丝毫关系,顶多就是0x0A借用了字符'A'而已。故如果想在屏幕上输出字符'A'可将其转义字符直接插入输出流中,或者将0x41转化为字符类型,然后插入,不得使用0x41直接插入,因为0x41本身是int类型的10进制数65。同时也不可以将'0x41'直接插入输出流,因为'0x41'是int类型的数。
?? 可以尝试使用控制符std::hex来插入字符'a'到输出流。
posted on 2007-01-15 10:59
仄洛
阅读(24)
评论(0)
编辑
收藏
收藏至365Key
所属分类:
C++ Performance
帮朋友发个招聘公告
:【上一篇】
Finding Nemo
:【下一篇】
【相关文章】
没有相关文章
【随机文章】
JMX 入门学习-(1)创建一个MBean
Oracle数据库整机移植技术
Newt文件系统的VFS分析(2)
mysql使用password()加密后如何查询
分享个极好的ajax二级联动下拉列表,同样适用与firefox
考SCJP的失败经历
javascript基础知识
CCNP学习的笔记-AAA篇
边框扮靓数码照片
Simple vsftp setup
【相关评论】
没有相关评论
【发表评论】
姓名:
邮件:
随机码
*
:
评论
*
:
|
首 页
|
版权声明
| 联系我们
|
网站地图
|
CopyRight © 2004-2007 软讯网络 All Rigths Reserved.