如何序列化" std :: string"使用tpl

时间:2014-11-20 15:09:29

标签: c++ c serialization stdstring

    std::string content = readFile();
char *carray = const_cast<char*>(content.c_str());
tpl_node *tn = tpl_map("s", carray);
tpl_pack(tn, 0);
tpl_dump(tn, TPL_FILE, "player.dat");
tpl_free(tn);

我希望序列化std :: string到tpl_map(“s”,...),但它不起作用。 在

中抛出运行时异常
  

HelloCppWin32.exe!tpl_pack(tpl_node * r,int i)1864行

1 个答案:

答案 0 :(得分:0)

您必须将指针传递给char数组,而不是char数组。请注意从official TPL page

复制的受支持格式字符表中的额外*
Type    Description     Required argument type
s       string          char**

在你的情况下,那将是:

tpl_node * tn = tpl_map(“s”,&amp; carray);