1

我打算从文件中读取 protobuf 数据并在我的代码中使用它。我尝试进行一些逆向工程并将数据填充到我的文件中,并将日志文件中的字符串哑化。我现在阅读此日志文件并更改字段值并使用文件处理将其读取为字符串。但是,它似乎不起作用。我的代码有问题吗。

std::ifstream myprotobuf("/root/testfile.txt", std::ios::in | std::ios::binary);
if (myprotobuf)
{
    std::string string_in_file;
    myprotobuf.seekg(0, std::ios::end);
    contents.resize(myprotobuf.tellg());
    myprotobuf.seekg(0, std::ios::beg);
    myprotobuf.read(&string_in_file[0], contents.size());
    myprotobuf.close();
    RealMsg -> ParseFromString (string_in_file);
}
4

0 回答 0