如何将数据从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()
但这不起作用。 有任何线索怎么做?
答案 0 :(得分:4)
您可以尝试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() );