0
我有以下幾點:
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中的當前時間?
- 是不是有一個更簡單的方法來做到這一點?