如何“\x”工作在一个字符串? [英] How does "\x" work in a String?

查看:128
本文介绍了如何“\x”工作在一个字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个C / C ++程序,它涉及将一个数字的十六进制表示放入一个字符串中,我对 \x 如何工作感到困惑。我见过很多例子,例如\xb2。在这种情况下,程序如何知道你是否想要b的十六进制数,然后是数字2,或者如果你想要b2的十六进制数?另外,当它将它存储到memeory中时,它会保存\ x字符还是只保存十六进制表示? 解决方案

从C99标准(6.4.4.4):


每个八进制或十六进制转义序列是最长的字符序列,它们可以是
构成转义序列。



I'm writing a C/C++ program that involves putting a hex representation of a number into a string and I'm confused as to how \x works. I've seen examples where people have written things such as "\xb2". In this case, how does the program know if you want the hex of b followed by the number 2 or if you want the hex of b2? Additionally, when it stores this into memeory does it save the "\x" characters or does it just save the hex representation?

解决方案

From the C99 standard (6.4.4.4):

Each octal or hexadecimal escape sequence is the longest sequence of characters that can constitute the escape sequence.

这篇关于如何“\x”工作在一个字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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