本文介绍了如何使用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

推荐答案




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


-

Unforgiven



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

--
Unforgiven





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


-

Unforgiven



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

--
Unforgiven




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


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




或者,


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



Or,

cout << int( Test ) << endl;


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

10-28 07:53