【问题标题】:Complex format specifier C复杂格式说明符 C
【发布时间】:2016-09-05 11:12:36
【问题描述】:

谁能解释一下下面代码中的说明符之王是什么?并举个例子。

printf("\r\x1b[32mConverting: \x1b[36m%d\x1b[0m",(Convert));

【问题讨论】:

  • 请澄清您的具体问题或添加其他详细信息以准确突出您的需要。正如目前所写的那样,很难准确地说出你在问什么。请参阅“如何提问”页面以获得澄清此问题的帮助。

标签: c format specifier


【解决方案1】:

这些 ascii 特殊代码用于为调试消息着色。 \x1b[32m 为“convering”赋予绿色 \x1b[36m%d 将青色赋予转换整数 和 \x1b[0m%d 最终重置颜色值。 \r 是回车

%d 只是整数的格式说明符 https://www.quora.com/What-does-d-mean-in-the-C-programming-language

【讨论】:

  • 解释首字母\r,你的答案就完整了。
【解决方案2】:

字符串包含两个ANSI escape codes。要找出它们的含义 \x1b[ 在链接的文章中用 CSI 表示,例如\x1b[32m 对应于维基百科由CSI n m 表示的内容:

CSI n m
SGR – Select Graphic Rendition
Sets SGR parameters, including text color. After CSI can be zero or more parameters separated with ;. With no parameters, CSI m is treated as CSI 0 m (reset / normal), which is typical of most of the ANSI escape sequences.

【讨论】:

  • \x1b 和 36m%d 是什么?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-01
  • 1970-01-01
相关资源
最近更新 更多