[英]How to insert in middle of stringstream during serialisation?
std::ostringstream oss;
boost::archive::text_oarchive oa(oss);
我將可變數量的內容添加到此oa中,就像這樣
oa & int1;
oa &int2;
--------------------> insert number of matrices here
oa & matrix1;
..//do some processing
oa & matrix2;
...//do some more
....
oa & matrixn;
矩陣參考-http: //robot.kaist.ac.kr/haptics/chai3d-2.0.0_Doc/resources/html/structc_matrix3d.html
現在,當我結束時,我想在udp發送之前添加我添加到此歸檔文件中的矩陣數,然后再開始添加矩陣。 但是我也知道在將它們添加到流中之后添加了多少個矩陣
我應該怎么做?
你做不到
oa & matrix1.
為此,矩陣必須是簡單類型(不是)或實現序列化功能。 您可以覆蓋矩陣實現序列化,然后使用它。
這是一個很好的參考: http : //www.boost.org/doc/libs/1_54_0/libs/serialization/doc/tutorial.html
實際上,您可以以oss <<(int)0開始; 然后,將所有seekp都寫回到開頭,並用添加的項數重寫前4個字節。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.