【问题标题】:how to serialize "std::string" using tpl如何使用 tpl 序列化“std::string”
【发布时间】:2015-01-18 12:12:06
【问题描述】:
    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 行 C

【问题讨论】:

    标签: c++ c serialization stdstring


    【解决方案1】:

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

    Type    Description     Required argument type
    s       string          char**
    

    在你的情况下,那将是:

    tpl_node *tn = tpl_map("s", & carray);

    【讨论】:

    • 谢谢,我试试看。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多