Short Version:
I have a String: 0x4D;0x90;0x69
I want an array
static const uint8_t array[] = {
0x4D, 0x90, 0x69
}
How to do?
Longer Version:
I have an String (buffer
) with like this: 0x4D0x900x69
between those hex "numbers" are Zero Width Spaces, and I split those up into a vector of strings using
std::vector<std::string> v{ explode(buffer, '\u200B') };
I want for to have an Vector with uint8_t
data in it.
I already tried to reinterpret_cast the string, and that actually worked. But I have put it in a forloop an it should push the result into an uint8_t
Vector, but in the Vector were only 0x00
in it.
std::vector < std::string > v {
explode(buffer, '\u200B')
};
std::vector < uint8_t * > ob;
for (auto n: v) {
uint8_t * p = reinterpret_cast < uint8_t * > ( & n);
//std::cout << n << " | " << p << std::endl;
ob.push_back(p);
};
for (auto na : ob) std::cout << na << std::endl;
I only get three 0x00 in the console.
I want to have an static const uint8_t arr[]
containing the buffer
splited up.
Edit:
I have forgot to add the explode
function here, its basicly just a split. ```cpp
const std::vector<std::string> explode(const std::string& s, const char& c)
{
std::string buff{ "" };
std::vector<std::string> v;
for (auto n : s)
{
if (n != c) buff += n; else
if (n == c && buff != "") { v.push_back(buff); buff = ""; }
}
if (buff != "") v.push_back(buff);
return v;
}