如何使用cout显示char的十进制值? [英] How to show decimal value of a char using cout?

查看:151
本文介绍了如何使用cout显示char的十进制值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我还在学习C ++,所以我不确定我要做的是

。她是一个简单的例子:


char Test =''L'';

cout<< 测试字符为十进制: << dec<<测试<< endl;


在上面的cout语句中,我希望它会显示76,即L字符的

十进制值。相反,它显示了L.是否有使用cout来显示价值的方式?


我知道我可以用printf完成这个,但是想要看看cout

也可以做到。提前致谢。


查理

Hello everyone,

I am still learning C++, so I''m not sure what I''m trying to do is
possible. Her is a simplified example:

char Test = ''L'';
cout << "Test Char as decimal: " << dec << Test << endl;

In the above cout statement, I was hoping it would show 76, the
decimal value of the L character. Instead, it displays an L. Is there
a way to use cout to show the value?

I know I can accomplish this with printf, but wanted to see if cout
could also do it. Thanks in advance.

Charlie

推荐答案

" Charles Kerekes" < CH ************ @ yahoo.com>在消息中写道

news:8e ************************** @ posting.google.c om ...
"Charles Kerekes" <ch************@yahoo.com> wrote in message
news:8e**************************@posting.google.c om...
大家好,

我还在学习C ++,所以我不确定我要做的是
可能。她是一个简单的例子:

char Test =''L'';
cout<< 测试字符为十进制: << dec<<测试<< endl;
Hello everyone,

I am still learning C++, so I''m not sure what I''m trying to do is
possible. Her is a simplified example:

char Test = ''L'';
cout << "Test Char as decimal: " << dec << Test << endl;




cout<< static_cast< int>(测试)<<结束;


-

Unforgiven



cout << static_cast<int>(Test) << endl;

--
Unforgiven


" Charles Kerekes" < CH ************ @ yahoo.com>在消息中写道

news:8e ************************** @ posting.google.c om ...
"Charles Kerekes" <ch************@yahoo.com> wrote in message
news:8e**************************@posting.google.c om...
大家好,

我还在学习C ++,所以我不确定我要做的是
可能。她是一个简单的例子:

char Test =''L'';
cout<< 测试字符为十进制: << dec<<测试<< endl;
Hello everyone,

I am still learning C++, so I''m not sure what I''m trying to do is
possible. Her is a simplified example:

char Test = ''L'';
cout << "Test Char as decimal: " << dec << Test << endl;




cout<< static_cast< int>(测试)<<结束;


-

Unforgiven



cout << static_cast<int>(Test) << endl;

--
Unforgiven


Unforgiven写道:
Unforgiven wrote:
Charles Kerekes < CH ************ @ yahoo.com>在消息中写道
新闻:8e ************************** @ posting.google.c om ...
"Charles Kerekes" <ch************@yahoo.com> wrote in message
news:8e**************************@posting.google.c om...
大家好,

我还在学习C ++,所以我不确定我要做的是
可能。她是一个简单的例子:

char Test =''L'';
cout<< 测试字符为十进制: << dec<<测试<< endl;
Hello everyone,

I am still learning C++, so I''m not sure what I''m trying to do is
possible. Her is a simplified example:

char Test = ''L'';
cout << "Test Char as decimal: " << dec << Test << endl;



cout<< static_cast< int>(测试)<< endl;


cout << static_cast<int>(Test) << endl;




或者,


cout<< int(测试)<< endl;



Or,

cout << int( Test ) << endl;


这篇关于如何使用cout显示char的十进制值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆