>"-6ren"> >"-no suitable constructor exists to convert from "uint8_t *" to "std::vector>" 类型转换不工作 编辑: const std::-6ren">
gpt4 book ai didi

c++ - 不存在合适的构造函数来从 "uint8_t *"转换为 "std::vector>"

转载 作者:搜寻专家 更新时间:2023-10-31 01:20:12 25 4
gpt4 key购买 nike

no suitable constructor exists to convert from "uint8_t *" to "std::vector<uint8_t, std::allocator<uint8_t>>"

类型转换不工作

编辑:

const std::vector<uint8_t> Test (const std::vector<uint8_t> buffer) const;

uint8_t* buffer="...";

//so i can use Test() function
Test(buffer);

Error
no suitable constructor exists to convert from "uint8_t *" to "std::vector<uint8_t, std::allocator<uint8_t>>"

最佳答案

您不能将array 转换为std::vector,您需要显式构造一个。一种方法是像这样使用 vector 的范围构造函数:

uint8_t* buffer="...";
// +1 for the terminating \0
std::vector<uint8_t> vector( buffer, buffer + strlen( buffer ) + 1 );
Test( vector );

作为旁注,如果您的缓冲区嵌入了 \0,则 strlen 将返回不正确的值。作为解决方法,您可以执行以下操作:

uint8_t[] buffer="...";
std::vector<uint8_t> vector( buffer, buffer + sizeof( buffer ) );
Test( vector );

关于c++ - 不存在合适的构造函数来从 "uint8_t *"转换为 "std::vector<uint8_t, std::allocator<uint8_t>>",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5135123/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com