生成的xml,其他地方都正常,就“ftpport”的属性总是显示乱码,开始以为是toString函数的问题,但是我换了一种转换方式后这个问题依然存在,同时我调试的时候看到的toString
的返回值也正常,最后和同时讨论后,他给我解释rapidxml的函数在创建新节点或者属性的时候,传入的参数要么是由内部分配器分配的内存要么应该指向一块短期内不会被释放的内存。
原来如此,于是我改了代码之后rapidxml::xml_node<>* srvnode = doc.allocate_node(rapidxml::node_element,iter->m_name.c_str(),""); srvnode->append_attribute(doc.allocate_attribute("ip",iter->m_ip.c_str())); char* port = doc.allocate_string(toString(iter->m_ftpport).c_str()); srvnode->append_attribute(doc.allocate_attribute("ftpport",port));
写在这里纯粹是做个记录,希望对某些同志也有帮助!