【发布时间】:2014-09-05 07:04:31
【问题描述】:
.proto 文件结构
message repetedMSG { 所需的字符串数据 = 1; }
message mainMSG
{
required repetedMSG_id = 1;
repeated repetedMSG rptMSG = 2;
}
我有一个 mainMSG,其中存在太多(假设 10 个)repetedMSG。 现在我想从 mainMSG 中删除任何特定的 repetedMSG(假设是第 5 个 repetedMSG)。为此,我尝试了 3 种方法,但都没有奏效。
for (int j = 0; j<mainMSG->repetedMSG_size(); j++){
repetedMSG reptMsg = mainMsg->mutable_repetedMSG(j);
if (QString::fromStdString(reptMsg->data).compare("deleteMe") == 0){
*First tried way:-* reptMsg->Clear();
*Second tried Way:-* delete reptMsg;
*Third tried way:-* reptMsg->clear_formula_name();
break;
}
}
当我序列化 mainMSG 以写入文件时,即执行此行时,出现运行时错误
mainMSG.SerializeToOstream (std::fstream output("C:/A/test1", std::ios::out | std::ios::trunc | std::ios::binary)) 在这里我得到运行时错误
【问题讨论】:
标签: protocol-buffers