Как получить двоичные данные из boost :: asio :: streambuf - PullRequest
3 голосов
/ 04 февраля 2011

Как я могу сбросить данные из 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()

, но это не сработало.Любая подсказка, как это сделать?

1 Ответ

4 голосов
/ 05 февраля 2011

Вы можете попробовать 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() );
...