告诉转义的十六进制以字符串结尾的位置 [英] Tell where escaped hexadecimal ends in a string

查看:67
本文介绍了告诉转义的十六进制以字符串结尾的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 printffunction

I want to print 10°Celsius with printffunction

通常我会这样做:

printf("10\xF8Celsius");

其中 \xF8 是度数符号的 ANSI 代码.问题是编译器取\x 之后的所有十六进制字符并尝试转换为字符,基本上它取\F8Ce 并尝试将其转换为字符.

where \xF8 is the ANSI code for degree sign. The problem is that the compiler take all hexadecimal characters after \x and tries to convert to a character, basically it takes \F8Ce and tries to convert it to a character.

我可以这样写:

printf("10\xF8 Celsius"); //see additional space

但问题仍然存在.

如何告诉编译器我的十六进制代码在哪里结束?可能吗?

How to tell compiler where my hexadecimal code ends? Is it possible?

注意:我在 Windows 8.1 上使用 Visual Studio 2015 PRE 来观察这个问题(不是这个问题是特定于平台的,只是提一下)

Note: I used Visual Studio 2015 PRE on a Windows 8.1 to observe this problem (not that this problem is platform specific but just to mention it)

推荐答案

来自 这个 C++ 转义序列参考:

十六进制转义序列没有长度限制,并在第一个不是有效十六进制数字的字符处终止.

Hexadecimal escape sequences have no length limit and terminate at the first character that is not a valid hexadecimal digit.

因此,如果没有任何解决方法,编译器将读取的数字就没有限制.

So without any workarounds there is simply no limit on the digits the compiler will read.

请注意,相应的 C 参考 也说了同样的话.

Note that the corresponding C reference says the same thing.

这篇关于告诉转义的十六进制以字符串结尾的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆