我使用Boost將窗體「01-Jan-2000」的日期轉換爲朱利安數字。我這樣做的方式是使用是否std :: istringstream :: imbue擁有傳遞的對象
int toJulian(std::string date)
{
std::locale loc = std::locale(std::locale::classic(), new boost::posix_time::time_input_facet("%d-%b-%Y"));
std::istringstream ss(date);
ss.imbue(loc);
boost::posix_time::ptime p;
ss >> p;
return p.date().julian_day();
}
(這是在Boost文檔中的示例中)。
但我不清楚這是否泄漏內存或不。我沒有明確的delete
。顯然,如果imbue
將loc
中指針的所有權傳遞給流,那麼當ss
超出範圍時可能會將其刪除。
我正確嗎?
見http://www.boost.org/doc/libs/1_43_0/doc/html/date_time/date_time_io.html#date_time.format_flags
cppreference上的例子似乎也沒有刪除'Facet'。有趣的是,它沒有提到這一點。通常我會假設原始指針意味着沒有擁有... –
@BartekBanachewicz:盜用你的風頭:cppreference.com有一個說明,說明區域設置刪除。 – Bathsheba