我有一个奇怪的问题。我有一个需要返回到另一个函数的数组。问题是它必须被输出/转换为
(unsigned)(unsigned char)
处理数据的函数是 char* 类型。这是我在其中转换数据的函数:
char* Wav::readHeader(ifstream &file)
{
file.read(this->chunkId, 4);
file.read(reinterpret_cast<char*>(&this->chunkSize), 4);
file.read(this->format, 4);
file.read(this->formatId, 4);
file.read(reinterpret_cast<char*>(&this->formatSize), 4);
file.read(reinterpret_cast<char*>(&this->format2), 2);
file.read(reinterpret_cast<char*>(&this->numChannels), 2);
file.read(reinterpret_cast<char*>(&this->sampleRate), 4);
file.read(reinterpret_cast<char*>(&this->byteRate), 4);
file.read(reinterpret_cast<char*>(&this->align), 2);
file.read(reinterpret_cast<char*>(&this->bitsPerSample), 4);
char testing[4] = {0};
int testingSize = 0;
while(file.read(testing, 4) && (testing[0] != 'd' ||
testing[1] != 'a' ||
testing[2] != 't' ||
testing[3] != 'a'))
{
file.read(reinterpret_cast<char*>(&testingSize), 4);
file.seekg(testingSize, std::ios_base::cur);
}
this->dataId[0] = testing[0];
this->dataId[1] = testing[1];
this->dataId[2] = testing[2];
this->dataId[3] = testing[3];
file.read(reinterpret_cast<char*>(&this->dataSize), 4);
this->data = new char[this->dataSize];
file.read(data, this->dataSize);
for(unsigned i=0; (i < 20); i++)
{
//cout << (unsigned)(unsigned char)data[i] << endl;
}
return (unsigned)(unsigned char) data;
}
在另一个函数中,我有这个:
unsigned char* data = this->readHeader(file);
谁能看到我哪里出错了?
谢谢 :)