printf(“%cx”,FILE2CHAR(F(fr)))到cout [关闭](printf(“%cx”, FILE2CHAR(F(fr))) to cout [closed])

编程入门 行业动态 更新时间:2024-10-24 21:22:18
printf(“%cx”,FILE2CHAR(F(fr)))到cout [关闭](printf(“%cx”, FILE2CHAR(F(fr))) to cout [closed])

如何用“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.

更多推荐

本文发布于:2023-07-22 19:29:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1222759.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:FILE2CHAR   cx   printf   closed   cout

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!