Reputation: 157
HI,
I have the following:
class pers
{
public:
pers();
std::string name;
long favourite_number;
time_t curent_time;
}
I would like to create an xml using tinyXml. Here is the xml:
<data>
<name> me </name>
<favourite_number> 1233336555 </favourite_number> //it's a long number
<curent_time> hour:day:month:year </curent_time>
And here is the code:
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 );
Upvotes: 0
Views: 1329
Reputation: 20038
So your question basically has nothing to do with XML, nor TinyXml? Next time you might want to simplify your question and give it an appropriate title.
You can either go via time.h and the functionality provided in there or use something like Boost.Date_Time. Something which was answered here as well.
Upvotes: 1