将Boost的BufferStream转换为Istream
Convert boost`s bufferstream to istream
是否可以将Boost的BufferStream转换为Istream?我正在尝试进行转换,但是我仍然不清楚我是做错了什么还是根本无法做到这一点。我很感谢任何答案。
char *copy = static_cast <char*> (region.get_address());
for (int i = 0;i < length;i++) copy[i] = str[i];
bufferstream input_stream (copy, length);
然后我需要将BufferStream转换为ISTream。基本上,我需要将BufferSeam实例作为参数传递给接受IStream&amp;的函数。
这是不清楚的您想实现什么,这是我最好的猜测:
live coliru
#include <boost/interprocess/mapped_region.hpp>
#include <boost/interprocess/shared_memory_object.hpp>
#include <boost/interprocess/streams/bufferstream.hpp>
#include <iostream>
namespace bip = boost::interprocess;
int main() {
bip::shared_memory_object smo(bip::open_or_create, "MySharedMemory", bip::read_write);
std::string str = "test data";
smo.truncate(10ull << 10); // 10 KiB
bip::mapped_region r(smo, bip::read_write);
bip::bufferstream stream(reinterpret_cast<char*>(r.get_address()), r.get_size());
if (stream << str)
std::cout << "Written";
}
¹https://meta.stackexchange.com/questions/66377/what-is-the-problem
²Coliru
相关文章:
- 防止主数据类型C++的隐式转换
- 模板参数替换失败,并且未完成隐式转换
- 将无符号char*转换为std::istream*C++
- 如何将QByteArray转换为std::istream或std::ifstream?
- 如何在 c++ 中将 IStream 转换为 Base64 字符串
- 如何将常量无效*转换为istream?
- 将缓冲区转换为在现有程序中工作的iStream
- 将 istream 转换为 ifstream 时将 std::cin 传递到参数时出现问题
- 将Boost的BufferStream转换为Istream
- 将 boost::iostream::stream<boost::iostreams::source> 转换为 std::istream
- 如何将 ifstream 转换为 istream
- Istream 到字符串的转换,C++ 中的 个字符
- 将 istream 运算符>>转换为 istream getline
- 在窗口中将FILE*或HANDLE转换(ASSIGN)为IStream
- 如何将 istream * 转换为字符串或仅打印它
- 将istream转换为ifstream
- istream中发生了什么隐式转换?
- 如何将 std::istream 转换为 std::wistream
- 转换为python.使用boost::python时,将IO对象转换为std::istream
- 无法将“const char*”转换为“std::istream*”