Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/162.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将字符串转换为C++;? 如何在C++中转换字符串为uTI8*T?< /P> std::string str = "b2d"; static const uint8_t PublicKeyData[3] = ??? // it should be like 0x62 0x32 0x64}_C++ - Fatal编程技术网

如何将字符串转换为C++;? 如何在C++中转换字符串为uTI8*T?< /P> std::string str = "b2d"; static const uint8_t PublicKeyData[3] = ??? // it should be like 0x62 0x32 0x64}

如何将字符串转换为C++;? 如何在C++中转换字符串为uTI8*T?< /P> std::string str = "b2d"; static const uint8_t PublicKeyData[3] = ??? // it should be like 0x62 0x32 0x64},c++,C++,您可以使用以下函数复制所有字符串: #include <string> #include <cstdint> #include <algorithm> int main() { std::string str = "b2d"; uint8_t PublicKeyData[3]; std::copy(str.begin(), str.end(), PublicKeyData); } 您从哪里获得这些值(0x30、0x81、0x9D)?

您可以使用以下函数复制所有字符串:

#include <string>
#include <cstdint>
#include <algorithm>

int main() {
    std::string str = "b2d";
    uint8_t PublicKeyData[3];
    std::copy(str.begin(), str.end(), PublicKeyData);
}

您从哪里获得这些值(
0x30、0x81、0x9D
)?您想要什么?什么是
{0x30,0x81,0x9D}
?这些不是
“b2d”
@deidei Yes的ASCII码。我想获取字符串中每个元素的ASCII十六进制值。
std::copy(str.begin()、str.end()、PublicKeyData)
@LightAlex:这仍然不会从
“b2d”
生成
0x30 0x81 0x9D
,而是
0x62 0x32 0x64
。那你到底想做什么?
0x30 0x81 0x9D
实际上代表什么?也许是炸土豆条?你需要提供更多关于你想要完成什么的细节。您将使用
StringSource
做什么?
char PublicKeyData[3];