You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With ctime not being thread safe the suggested replacement is strftime for safety. Doing so requires a refactor of all time_t as well, since they can't be used with strftime and are also not thread safe.
Here's a small snippet that outputs the same values for both ctime and strftime
Input:
#include<iostream>
#include<ctime>intmain()
{
auto result = std::time(nullptr);
std::cout << std::ctime(&result) << std::endl;
char buffer [80];
auto t = std::time(nullptr);
auto lt = std::localtime(&t);
//TODO: check the return value to see if bytes are filledstd::strftime(buffer, 80, "%a %b %2d %T %Y%n", lt);
std::cout << buffer << std::endl;
return0;
}
Output:
> clang++-7 -pthread -std=c++17 -o main main.cpp
> ./main
Thu Oct 27 22:18:34 2022
Thu Oct 27 22:18:34 2022
>
With ctime not being thread safe the suggested replacement is strftime for safety. Doing so requires a refactor of all time_t as well, since they can't be used with strftime and are also not thread safe.
see:
ctime c++ ref
strftime c++ ref
The text was updated successfully, but these errors were encountered: