uint32 unCompressLength = 0; memcpy(&unCompressLength, md5p + LIVE_DATA_HEADER_LEN_OFFSET, BUFLEN__); char src[unCompressLength] = {0}; 报错error: variable-sized object may not be initialized char src[unCompressLength] = {0};,给出修改后代码
时间: 2024-02-25 12:58:33 浏览: 66
由于数组的长度需要在编译时确定,所以不能使用变量`unCompressLength`来定义数组。可以使用动态分配内存的方式来实现:
```
uint32 unCompressLength = 0;
memcpy(&unCompressLength, md5p + LIVE_DATA_HEADER_LEN_OFFSET, BUFLEN__);
char* src = new char[unCompressLength]();
```
注意在使用完`src`后需要手动释放内存:
```
delete[] src;
```
阅读全文