使用sscanf的Parsintg UUID

问题描述 投票:0回答:1

我正试图通过sscanf将UUID字符串解析为std :: array,但是出了点问题,我无法通过缝隙来找出问题所在:

std::array<uint8_t, 16> arr{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
sscanf("00112233-4455-6677-8899-AABBCCDDEEFF", 
    "%hhx%hhx%hhx%hhx-%hhx%hhx-%hhx%hhx-%hhx%hhx-%hhx%hhx%hhx%hhx%hhx%hhx", 
    &arr[0], &arr[1], &arr[2], &arr[3], &arr[4], &arr[5], &arr[6], &arr[7],
    &arr[8], &arr[9], &arr[10], &arr[11], &arr[12], &arr[13], &arr[14], &arr[15]
);

此数组之后包含0x33,0xab,0x89,0x67,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00。知道发生了什么事吗?

c++11 scanf uuid
1个回答
0
投票

您也需要指定宽度2

© www.soinside.com 2019 - 2024. All rights reserved.