簡體   English   中英

在C ++中使用Boost的命名管道序列化對象

[英]Serializing an object with Boost for Named Pipes in c++

我正在嘗試使用Boost庫對來自命令行應用程序的一些EEG數據進行序列化以進行序列化,並通過命名管道將該序列化的數據發送到Visual Studio C ++ 2010中內置的用戶界面Form。

從boost庫教程中,我可以序列化我的數據結構,並且http://www.boost.org/doc/libs/1_48_0/libs/serialization/doc/tutorial.html#simplecase

從Win32命名管道上的本教程中,我可以構造管道並在應用程序之間發送文本。 http://avid-insight.co.uk/joomla/component/k2/item/589-introduction-to-win32-named-pipes-cpp?tmpl=component&print=1

boost庫教程序列化一個文本文件:

std::ofstream ofs("filename");

// create class instance
const gps_position g(35, 59, 24.567f);

// save data to archive
{
    boost::archive::text_oarchive oa(ofs);
    // write class instance to archive
    oa << g;
    // archive and stream closed when destructors are called
}

我想知道要通過命名管道發送數據結構需要序列化什么? IOstream c ++庫似乎總是需要一個文件來流傳輸? http://www.cplusplus.com/reference/iostream/

我不想o序列化到文件,並且不確定要序列化到什么? 如果您能告訴我需要序列化的內容,我將不勝感激,如果您可以告訴我是否需要除boost :: archive :: text_oarchive之外的其他boost命令,那將是很棒的 ,因為我一直找不到替代。

感謝您的時間! 真的很感激!

(此問題之前曾被問過: 使用Boost?序列化並發送數據結構 ,但是該人員被告知不要使用boost,因為他的簡單數據結構boost將有太多開銷,因此它實際上仍在浮動。)

感謝ForEveR,非常簡單,不知道我是怎么想念它的! :)與上面發布的兩個教程結合使用的解決方案:

    const EEG_Info g(35, 59, 24.567f);
std::stringstream MyStringStream ;
boost::archive::text_oarchive oa(MyStringStream);
    // write class instance to archive
    oa << g;
// This call blocks until a client process reads all the data

string strData;
strData = MyStringStream.str(); 


DWORD numBytesWritten = 0;
result = WriteFile(
    pipe, // handle to our outbound pipe
    strData.c_str(), // data to send
    strData.length(), // length of data to send (bytes)
    &numBytesWritten, // will store actual amount of data sent
    NULL // not using overlapped IO
);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM