1.整个文件完全读入
#include <iostream>
#include <memory>
#include <fstream>
std::ifstream is;
is.open("D:\\1.wav", std::ios::in | std::ios::binary);
if(!is.is_open())
{
return;
}
is.seekg(0, is.end);
size_t in_wave_bytes = is.tellg();
is.seekg(0, is.beg);
std::shared_ptr<char> shptrData(new char[in_wave_bytes ]);
is.read(shptrData.get(), in_wave_bytes );
is.close();
2.写入文件
std::ofstream os;
os.open(path, std::ios::out | std::ios::binary);
if (!os.is_open())
{
return;
}
os.write((const char *)pWavFile,Lenth); //写入的内容及长度
os.close();