Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我试过了swprintf(buff, 4, L"%#03x", value),但是当value = 0我得到000而不是0x0。
swprintf(buff, 4, L"%#03x", value)
value = 0
000
0x0
您需要文字中的“0x”,例如“0x%03x”。该x格式仅以十六进制打印数字,不添加 0x 装饰。
x
使用L"0x%x", value. 使缓冲区只有四个元素可能是一个坏主意(只要value大于0xF)。您应该存储返回值并确保字符串没有被截断:
L"0x%x", value
value
0xF
int n = swprintf(buff, sizeof buff, L"0x%x", value); if (n >= sizeof buff) { /* truncation! */ }