目前我有一个程序将二进制数据加载到字符串流中,然后将数据压缩到fstream,如下所示:
stringstream ss(stringstream::binary | stringstream::in | stringstream::out);
ss.write(data, 512); // Loads data into stream
// Uses a memory block to pass the data between the streams
char* memBlock = new char[512];
ss.read(memBlock, 512);
ofstream fout("someFile.bin", ios::binary);
fout.write(memBlock, 512); // Writes the data to a file
fout.close();
delete[] memBlock;
我的问题是:是否有更好的方法在流之间传递二进制数据?