size_t fread ( void *buffer, size_t size, size_t count, FILE *stream)
;
参 数
buffer:用于接收数据的内存地址
size:要读写的字节数,单位是字节
count:要进行读写多少个size字节的数据项,每个元素是size字节.
stream:输入流
读取wav文件头的示例
struct wavhdr{ char riff[4]; //<span style="color: rgb(102, 102, 102); font-family: verdana, sans-serif; font-size: 16px; line-height: 21px;">"RIFF"标志 </span> unsigned long FileSize;//<span style="color: rgb(102, 102, 102); font-family: verdana, sans-serif; font-size: 16px; line-height: 21px;">文件长度 </span> char wave[4]; char fmt[4]; unsigned long wFormatLength; unsigned short wFormatTag; unsigned short nChannels; unsigned long nSamplesPerSec; unsigned long nAvgBytesPerSec; unsigned short nBlockAlign; unsigned short wBitsPerSample; char data[4]; unsigned long datasize; };
<pre name="code" class="cpp"> FILE * pFile = NULL; pFile = fopen(filepath.c_str(), "rb"); if (pFile != NULL) { wavhdr pWav; fread(pWav.riff,4,1,pFile); //读取4个字节 fread(&(pWav.FileSize),1,4,pFile);//读取1个字节 fclose(pFile); }
时间: 2024-10-12 03:27:39