demo:
#include <iostream> #include <iomanip> using namespace std; int main() { char *ch; void *in; int i=0x11223344,j; in=&i; ch=(char*)in; for(j=0;j<4;j++) {
/*setiosflags(ios_base::hex)不起作用*/ cout<<hex<<(int)*(ch+j)<<endl;//hex输出必须对应int类型,否则输出ASCII码 } return 0; }