boost - 如何从 boost::asio::streambuf 获取二进制数据

标签 boost boost-asio

如何将数据从 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/

相关文章:

c++ - 提升 asio receive() 与 read()

boost-asio - boost.asio,如何使用asio读取一个完整的IP包

c++ - boost asio 绑定(bind)端点

c++ - 编译 boost::geometry 多边形

c++ - 在 C++ 中标记 "Braced Initializer List"样式的字符串(使用 Boost?)

c++ - 如何调用绑定(bind)了所有参数的 boost::function 对象

c++ - 阻止取消 Boost.Asio 中挂起的异步操作

c++ - 在没有虚拟原型(prototype)的情况下调用继承类的一种方法

c++ - 奇怪的程序挂起,这在调试中意味着什么?

c++ - boost .Asio : Could I cancel a SYNCHRONOUS operation running in a secondary thread?