Std :: vector hexadecimal values

How to initialize std::vector with hexadecimal values? The following produces an error:

 std::vector<unsigned char> vect ("oc","d4","30"); 

If I have a string value that contains base64 code, for example: "DNQwSinfOUSSWd + U04r23A ==" .... how can I put it in std :: vectorv?

std :: string = "DNQwSinfOUSSWd + U04r23A ==";

First I want to decode it in hexa values. After that put it in the vector. Can someone please tell me how to decode a string value containing base64 encoder in hexa?

+4
source share
1 answer

(You forgot to specify the type of the std::vector element. I assume unsigned char .)

In C ++ 0x you can write:

 std::vector<unsigned char> v{ 0x0C, 0xD4, 0x30 }; 

In C ++ 03 you should write:

 std::vector<unsigned char> v; v.push_back(0x0C); v.push_back(0xD4); v.push_back(0x30); 

Or, if you don't mind using space:

 unsigned char values[] = { 0x0C, 0xD4, 0x30 }; std::vector<unsigned char> v(values, values+3); 

You can also see boost.assign .

+13
source

Source: https://habr.com/ru/post/1335387/


All Articles