我的程序通过TCP-Connection接收二进制数据。使用boost::asio
库建立连接。读取流后,我需要将接收到的数据作为char*
- 数组返回。这是我到目前为止所得到的:
char* read()
{
boost::system::error_code ec;
boost::asio::streambuf response;
size_t bytes = boost::asio::read(this->socket_, response, ec);
if(ec.value() != boost::system::errc::success)
{
cout << "In " << BOOST_CURRENT_FUNCTION << ": " << ec.category().name() << ':' << ec.value() << endl;
return "";
}
std::istream stream(&response);
char* ret = new char[bytes]{0};
int i = 0;
while(!stream.eof())
{
// ..??.. Write into char array
i++;
}
}
我正在寻找一个函数将接收到的二进制数据写入char数组。