你好,
我有以下内容:
class pers
{
public:
pers();
std::string name;
long favourite_number;
time_t curent_time;
}
我想使用 tinyXml 创建一个 xml。这里是xml:
<data>
<name> me </name>
<favourite_number> 1233336555 </favourite_number> //it's a long number
<curent_time> hour:day:month:year </curent_time>
这是代码:
main()
{
pers *p = new pers();
pers->name="me";
pers->favourite_number=12333336555;
/**/how too print the curent time ?**
TiXmlDocument doc;
TiXmlElement * root;
root = new TiXmlElement( "data" );
TiXmlElement * element1 = new TiXmlElement( "name" );
root->LinkEndChild( element1);
TiXmlText * text1 = new TiXmlText( pers->name );
element1->LinkEndChild( text1 );
TiXmlElement * element2 = new TiXmlElement( "favourite_number" );
root->LinkEndChild( element2);
long d=pers->favourite_number;
std::ostringstream os;
os << d;
std::string buf2=os.str();
TiXmlText * text2 = new TiXmlText( buf2 );
element2->LinkEndChild( text2 );
- 如果我想在 xml 中有当前时间,该怎么做?
- 没有更简单的方法吗?