将格式化的printf(c)等效于C++中的格式化cerr

Geo*_*e B 7 c c++ printf

我要为等效printf("%2.2x", var);cerr<<在C++中.
码:

typedef unsigned char byte;  
static byte var[10];  
for(i=1; i<10; i++)  
   printf("%2.2x", var[i]);
Run Code Online (Sandbox Code Playgroud)

我的想法是将调试重定向到这样的文件:./myprog 2>out.txt.
如果我不要求太多,我也想收到解释.
谢谢!

nul*_*ptr 14

使用fprintf(stderr, ...),例如:

fprintf(stderr, "%2.2x", var[i]);
Run Code Online (Sandbox Code Playgroud)