我想将boost :: asio :: streambuf转换成std :: string。
我该如何轻松做到这一点?如何将boost :: asio :: streambuf转换为std :: string?
3
A
回答
1
没试过,但如果我正确地阅读文档,这个类从std::streambuf
继承,在这种情况下,你可以这样做:
std::istream buffer(my_asio_streambuf_ptr);
std::stringstream string_buffer;
buffer >> string_buffer.rd_buf();
有很多方法可以做到这一点,每个人都有它的优点和缺点。如果你能更详细地解释你的问题,我们可以提供更具体的帮助。
0
像这样的东西可能是你追求的:
boost::asio::streambuf myBuffer;
std::string myString;
// Convert streambuf to std::string
std::istream(&myBuffer) >> myString;
5
我用这种形式给出:
boost::asio::streambuf stream_buf;
...
std::string s((std::istreambuf_iterator<char>(&stream_buf)), std::istreambuf_iterator<char>());
你可以阅读从其他类型的数据流,F.E.,ifstream的整体数据。
相关问题
- 1. 将std :: string转换为boost :: asio :: streambuf
- 2. boost :: asio :: async_read和boost :: asio :: streambuf
- 3. 何时调用boost :: asio :: streambuf :: consume()和boost :: asio :: streambuf :: commit()?
- 4. Boost ASIO ForwardIterator for streambuf
- 5. 如何将System :: String ^转换为std :: string?
- 6. 如何连接两个boost :: asio :: streambuf的?
- 7. 如何从Boost ASIO streambuf读取?
- 8. 将std :: __ cxx11 :: string转换为std :: string
- 9. 如何将std :: string转换为boost :: gregorian :: date?
- 10. 如何将unicode QString转换为std :: string?
- 11. 如何将char []转换为std :: string
- 12. 如何将wchar_t *转换为std :: string? ?
- 13. 如何将std :: string转换为LPCSTR?
- 14. 如何将Glib :: ustring转换为std :: string?
- 15. 将NSString转换为std :: string
- 16. 将std :: string转换为QString
- 17. 将std :: string转换为QwtText
- 18. 将uint64_t转换为std :: string
- 19. 将void *转换为std :: string
- 20. 将std :: string转换为char
- 21. 将std :: string转换为basic_ostream?
- 22. 如何将std :: string指针转换为std :: string
- 23. boost :: asio :: streambuf断言“迭代器出界”
- 24. C++/CX:将std :: string转换为Platform :: String^
- 25. 将std :: ostream转换为std :: string
- 26. boost :: asio :: streambuf缩小到适合?
- 27. 将boost std :: string :: const_iterator转换为字符串和int C++
- 28. boost :: asio :: streambuf - 链接器错误
- 29. 将boost :: bimap转换为std :: map
- 30. 错误C2664从常量的std :: string转换为的std :: string&
这将只抓取第一组字符。它在读入空格时会停止。 – 2013-04-22 06:37:17