stream.html
我正在考虑使用它作为tcp流和can总线之间的中间缓冲区。我将缓冲区传递给与写入can总线有关的API,后者使用async_reads获取数据。tcp端使用async_writes写入缓冲区。
发布于 2017-09-07 22:13:20
好的。
boost::asio::streambuf sb;
// now write:
{
std::ostream os(&sb);
os << "Hello 1 2 3" << std::flush;
}
// or read:
{ std::istream is(&sb);
std::string s;
int a, b, c;
is >> s >> a >> b >> c;
}请注意,还可以使用连接到套接字的预先配置的流:
#include <boost/asio.hpp>
#include <iostream>
using boost::asio::ip::tcp;
int main() {
tcp::iostream s("localhost", "http");
s << "GET / HTTP/1.0\r\n\r\n" << std::flush;
std::cout << s.rdbuf(); // print response
}https://stackoverflow.com/questions/46081761
复制相似问题