
02.10.2020, 11:32
|
|
Флудер
Регистрация: 26.10.2013
Сообщений: 4,924
С нами:
6603505
Репутация:
183
|
|
Сообщение от _=Gigant=_
Converting a string to uint8_t array in C++
I want an std::string object (such as a name) to a uint8_t array in C++. The function reinterpret_cast rejects my string. And since I'm coding using NS-3, some warnings are be...
stackoverflow.com
не знаешь - не советуй. По ссылке вообще другой кейс
Сообщение от Shypisaw
Есть строка : std::string str = "0x50, 0x20, 0x30";
Как конвертировать в массив uint8_t arr[] = { 0x50, 0x20, 0x30 };
C++:
Код:
std
::
stringstream
ss
(
"0x50, 0x20, 0x30"
)
;
std
::
string item
;
std
::
vector
arr
;
while
(
std
::
getline
(
ss
,
item
,
','
)
)
arr
.
push_back
(
std
::
stoll
(
item
,
nullptr
,
16
)
)
;
|
|
|