gpt4 book ai didi

stringstream - C++ 从 unsigned char* 到 stringstream : Segmentation fault (core dumped) error

转载 作者:行者123 更新时间:2023-12-02 03:36:33 29 4
gpt4 key购买 nike

<分区>

我正在编写 C++ 代码并尝试使用 stringstreamunsigned char* 数组转换为 string

代码片段:

 unsigned char * arr;
do{
fill(*arr);
//if I print the array here, the print operation works fine
stringstream s((const char*)arr); //I also tired other castings without success
cout<<s.str()<<endl;

//condition...
} while(condition);

do-while 因为我必须重复它。问题是我在此处遇到段错误(核心转储)错误:stringstream s((const char*)arr);


这是一个更详细的代码。 filllibusb_interrupt_transfer

int len = 64;
int transferred;
unsigned char *pkt = new unsigned char[len];
unsigned char * arr;
int arrLen;

do {
libusb_interrupt_transfer(handle, (EP_IN | LIBUSB_ENDPOINT_IN), pkt, len, &transferred, 1000);

arrLen = pkt[6];
arr = new unsigned char[arrLen];
for (int i = 0; i < arrLen; i++) {
arr[i] = pkt[i+7];
}
stringstream s;
s << (char*) arr;
}

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