首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >buffered_stream::buffered_stream构造函数中的Arg &a是什么?

buffered_stream::buffered_stream构造函数中的Arg &a是什么?
EN

Stack Overflow用户
提问于 2017-09-06 18:09:46
回答 1查看 140关注 0票数 1

stream.html

我正在考虑使用它作为tcp流和can总线之间的中间缓冲区。我将缓冲区传递给与写入can总线有关的API,后者使用async_reads获取数据。tcp端使用async_writes写入缓冲区。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-09-07 22:13:20

好的。

代码语言:javascript
复制
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;
}

请注意,还可以使用连接到套接字的预先配置的流:

代码语言:javascript
复制
#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
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46081761

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档