String into array two signs at once

Jan 11, 2015 at 1:28pm
Is there any way to write string like this: 00112233445566778899aabbccddeeff as an array like this:

 
unsigned char array[16]= {0x00 ,0x11 ,0x22 ,0x33 ,0x44 ,0x55 ,0x66 ,0x77 ,0x88 ,0x99 ,0xaa ,0xbb ,0xcc ,0xdd ,0xee ,0xff};

?

It has to be unsigned char array.
Jan 11, 2015 at 4:02pm
Yes.

Separate your string into substrings two characters long, apply std::stoi(str, nullptr, 16) to each and cast results in unsigned char.
Jan 11, 2015 at 4:29pm
How do I separate it?
Jan 11, 2015 at 4:55pm
Use substring member function http://en.cppreference.com/w/cpp/string/basic_string/substr
or
Manually copy each pair of symbols in temporary buffer
or
Insert '\0' character between each pair and do some obscure math
or
Think about your own method
Last edited on Jan 11, 2015 at 4:55pm
Jan 11, 2015 at 8:06pm
Thank you :)
Topic archived. No new replies allowed.