C++ Gio::OutputStream到字符串或std::ostream

C++ Gio::OutputStream到字符串或std::ostream,c++,glib,gtkmm,C++,Glib,Gtkmm,我正在使用libvtemm库,它有一个函数write\u contents。它获取一个内部缓冲区并将其输出到Glib::RefPtr对象。我一直在试图找到一种方法,将Gio::OutputStream的内容转换为std::string或类似的内容,这样我就可以处理其中的数据并将其移动到其他数据结构中 有人知道如何将Gio::OutputStream构造成类似std::ostream的东西,或者将其内容转换成std::string 我看到有一个Gio::MemoryOutputStream,像这样

我正在使用libvtemm库,它有一个函数
write\u contents
。它获取一个内部缓冲区并将其输出到
Glib::RefPtr
对象。我一直在试图找到一种方法,将Gio::OutputStream的内容转换为
std::string
或类似的内容,这样我就可以处理其中的数据并将其移动到其他数据结构中

有人知道如何将
Gio::OutputStream
构造成类似
std::ostream
的东西,或者将其内容转换成
std::string


我看到有一个
Gio::MemoryOutputStream
,像这样的东西在将数据抓取到
std::ostream
时有用吗?

对于那些正在寻找答案的人来说,下面是我将控制台缓冲区读入
std::string
的方法

// Create a mock stream just for this example
Glib::RefPtr<Gio::MemoryOutputStream> bufStream =
  Gio::MemoryOutputStream::create(NULL, 0, &realloc, &free);

// Create the stringstream to use as an ostream
std::stringstream ss;

// Get the stream size so we know how much to allocate
gsize streamSize = bufStream->get_data_size();
char *charBuf = new char[streamSize+1];

// Copy over the data from the buffer to the charBuf
memcpy(charBuf, bufStream->get_data(), streamSize);

// Add the null terminator to the "string"
charBuf[streamSize] = '\0';

// Create a string from it
ss << charBuf;
//仅为本例创建一个模拟流
Glib::RefPtr bufStream=
Gio::MemoryOutputStream::create(NULL、0、&realloc、&free);
//创建要用作ostream的stringstream
std::stringstream-ss;
//获取流大小,以便我们知道要分配多少
gsize streamSize=bufStream->get_data_size();
char*charBuf=新字符[streamSize+1];
//将数据从缓冲区复制到charBuf
memcpy(charBuf,bufStream->get_data(),streamSize);
//将空终止符添加到“字符串”
charBuf[streamSize]='\0';
//从中创建一个字符串
党卫军