如何将数据从 streambuf 刷新到文件? 我试过了
read(*socket_, streamBuf, boost::asio::transfer_at_least(694784))
std::istream is(&streamBuf);
std::ofstream outfile;
outfile.open ("test.exe");
is >> outfile;
outfile.close()
但这没有用。 知道如何做到这一点吗?
最佳答案
你可以试试 buffer_cast
.这是一个例子:
boost::asio::streambuf buf;
size_t bytes = read( *socket_, buf, boost::asio::transfer_at_least(694784) );
buf.commit( bytes );
std::ofstream outfile( "test.exe" );
outfile << boost::asio::buffer_cast<const char*>( buf.data() );
关于boost - 如何从 boost::asio::streambuf 获取二进制数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4896609/