Boost logo

Boost Users :

From: Richard (legalize+jeeves_at_[hidden])
Date: 2007-12-26 16:59:24


[Please do not mail me a copy of your followup]

boost-users_at_[hidden] spake the secret code
<47729C6C.3090409_at_[hidden]> thusly:

>But here's some example code:
>
>#include "boost/date_time.hpp"
>#include <iostream>
>
>using namespace boost::posix_time;
>using namespace boost::gregorian;
>
>
>int main()
>{
>
> ptime t1(date(2007, Dec, 26), hours(1) + seconds(5) + milliseconds(9));
>
> time_facet* timefacet = new time_facet("%a, %d %b %Y %H:%M:%S %z");
> std::cout.imbue(std::locale(std::locale::classic(), timefacet));
>
> std::cout << t1 << std::endl; //Wed, 26 Dec 2007 01:00:05
>}

I am always amazed when people superfluously use new. I am willing to
bet that superfluous use of new is responsible for quite a number of
C++ memory leaks and heap thrashing. Try:

int main()
{

   ptime t1(date(2007, Dec, 26), hours(1) + seconds(5) + milliseconds(9));

   time_facet timefacet("%a, %d %b %Y %H:%M:%S %z");
   std::cout.imbue(std::locale(std::locale::classic(), &timefacet));

   std::cout << t1 << std::endl; //Wed, 26 Dec 2007 01:00:05
}

-- 
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
      <http://www.xmission.com/~legalize/book/download/index.html>
        Legalize Adulthood! <http://blogs.xmission.com/legalize/>

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net