[英]How to copy binary data from one stream to another?
目前我有一个程序将二进制数据加载到字符串流中,然后将数据压缩到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;
我的问题是:有没有更好的方法在流之间传递二进制数据?
使用streambuf
成员,这就是他们的用途:
fout << ss.rdbuf();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.