从 xmlChar 修剪 t 不起作用

trimming from xmlChar not working

本文关键字:不起作用 修剪 xmlChar      更新时间:2023-10-16
#include "boost/algorithm/string/trim.hpp"
.
.
xmlChar *v = NULL;
cur = xmlDocGetRootElement(doc);
for (cur = cur->xmlChildrenNode; cur != NULL; cur = cur->next) {
    v =  xmlGetProp(cur, (const xmlChar *)"value");
    trim((char*)v);
    printf("%s",v);
}

这段代码无法编译,说修剪未定义,我尝试了 boost::trim,但没有帮助

。 谢谢。

boost::trim不适用于C字符串。使用 temp std::string 对象并将其传递给 boost::trim

std::string tmp((char*)v);
boost::trim(tmp);
std::cout << tmp;

看:trim.hpp。

在命名空间::boost::algorithm定义的函数。所以使用::boost::algorithm::trim(...).