C ++ cout十六进制格式 [英] C++ cout hex format
本文介绍了C ++ cout十六进制格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是一个c ++编码器,新到c ++。
i am a c coder, new to c++.
我尝试打印以下cout与奇怪的输出。对此行为的任何评论赞赏。
i try to print the following with cout with strange output. Any comment on this behaviour is appreciated.
#include<iostream>
using namespace std;
int main()
{
unsigned char x = 0xff;
cout << "Value of x " << hex<<x<<" hexadecimal"<<endl;
printf(" Value of x %x by printf", x);
}
输出:
Value of x ÿ hexadecimal
Value of x ff by printf
推荐答案
,iostreams可能是一个痛苦与他们的操纵者。要做任何有趣的人类可读输出,你可能想看看boost ::格式,它带来printf的所有喜悦到类型安全输出的世界。
also, iostreams can be a pain with their 'manipulators'. To do anything interesting for human readable output, you might want to look at boost::format, which brings all the joys of printf to the world of typesafe output.
这篇关于C ++ cout十六进制格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文