如何用“cout”表达printf("%cx", FILE2CHAR(F(fr))) ? (注意:FILE2CHAR(F(fr))返回一个int`)
我试过cout<<hex<<FILE2CHAR(F(fr)); 但在某些情况下,它仍然让我错误的十六进制。
我的错。 FILE2CHAR(F(fr))不返回int。 F(fr)返回一个int
FILE2CHAR是一个宏:
#define FILE2CHAR(f) ('a'+(f)) /* file to text */谢谢
你打算打印什么? %cx将打印一个字符,后跟x。 为什么还要使用六角机械手呢? - parkydr 因为我认为x指的是十六进制,我说对了吗? 有点混淆这里的语法。
How can i express printf("%cx", FILE2CHAR(F(fr))) with "cout"? (Note: FILE2CHAR(F(fr)) returns a int`)
I have tried cout<<hex<<FILE2CHAR(F(fr)); but which in some cases, it still returns me wrong hex.
My mistake. FILE2CHAR(F(fr)) does not return a int. F(fr) returns a int
FILE2CHAR is a Macro:
#define FILE2CHAR(f) ('a'+(f)) /* file to text */Thanks
What are you trying to print? %cx will print a character followed by x. Why use the hex manipulator anyway? – parkydr Because I thought x refers to hex, am I right? Kind of confused with the syntax here.
最满意答案
仍然有点困惑,所以我将涵盖这两种情况。
要打印字符,printf应该是
printf("%c", FILE2CHAR(F(fr)));流等价物是
cout << static_cast<char>(FILE2CHAR(F(fr)));强制转换是必需的,因为FILE2CHAR将返回一个整数,因此cout将显示整数值。
要打印十六进制值,printf应该是
printf("%x", FILE2CHAR(F(fr)));流等价物是
cout << hex << FILE2CHAR(F(fr));注意:在您使用dec操纵器之前,所有后续数字都将以十六进制显示。
Still a bit confused so I'll cover both situations.
To print a character, the printf should be
printf("%c", FILE2CHAR(F(fr)));The stream equivalent is
cout << static_cast<char>(FILE2CHAR(F(fr)));The cast is required because FILE2CHAR will return an integer so cout would display the integer value.
To print the hex value, the printf should be
printf("%x", FILE2CHAR(F(fr)));The stream equivalent is
cout << hex << FILE2CHAR(F(fr));Note: all subsequent numbers will be displayed in hex until you use the dec manipulator.
更多推荐
发布评论