2011-10-19 3 views
0

libvtemm 라이브러리를 사용하고 있는데이 함수는 write_contents입니다. 내부 버퍼를 취해 Glib::RefPtr<Gio::OutputStream> 개체로 출력합니다. Gio :: OutputStream의 내용을 std::string 또는 이와 비슷한 것으로 변환하여 다른 데이터 구조 내부에서 데이터를 재생할 수있는 방법을 찾으려고했습니다.Gio :: OutputStream을 String 또는 std :: ostream에

누군가 Gio::OutputStreamstd::ostream과 같은 것으로 구성하거나 내용을 std::string으로 변환하는 방법을 알고 있습니까?

나는 std::ostream에 자료를 움켜 쥐는 데 유용 할 것 같은 Gio::MemoryOutputStream가있는 것을 볼 수 있습니까?

답변

0

답변을 찾으시는 분들은 콘솔 버퍼를 읽으려고 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; 

앞으로이 문제가 비슷한 사람에게 도움이되기를 바랍니다.

관련 문제