Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need to delete the pointer returned by std::localtime?

Tags:

c++

This is currently how I am getting system time:

void Sum_AnalogClock::GetSystemTime()
{
    std::time_t t = std::time(0);   // get time now
    std::tm* now = std::localtime(&t);
    angleSeconds =  now->tm_sec;
    angleMinutes = now->tm_min;
    angleHours = now->tm_hour;
    if (angleHours > 12)
        angleHours -= 12;
}

Do I need to delete now;?

like image 259
Summit Avatar asked Jul 30 '26 06:07

Summit


1 Answers

No, according to [1] it points to an internal data structure, so you don't need to delete it.

[1] https://en.cppreference.com/w/cpp/chrono/c/localtime

like image 121
gerum Avatar answered Aug 01 '26 20:08

gerum



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!