繁体   English   中英

如何使用tpl序列化“ std :: string”

[英]how to serialize “std::string” using tpl

    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行

您必须将指针传递给char数组,而不是char数组。 请注意从官方TPL页复制的受支持格式字符表中的额外*:

Type    Description     Required argument type
s       string          char**

您的情况是:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM