Is there a builtin alternative to std::put_time for GCC <5?
There are no functions other than put_time
for the outputing of time provided in the chrono
or the iomanip
library.
The ctime
library does provide: strftime
, ctime
, and asctime
.
Since http://stackoverflow.com does not permit questions about finding 3rd party libraries, I'm going to guess that you're just asking for someone to direct you on the use of strftime
? std::put_time(c_time, "[%T%z %F] ")
could be written in the format:
char foo[24];
if(0 < strftime(foo, sizeof(foo), "[%T%z %F] ", c_time)) cout << foo << endl;
Also, this is C++, not C, so I'd like to steer clear of C functions whenever possible.
That's a pretty silly mindset. put_time
uses std::strftime
underneath the hood.
ext.manip#10
Returns: An object of unspecified type ... where the function
f
is defined as:
template <class charT, class traits>
void f(basic_ios<charT, traits>& str, const struct tm* tmb, const charT* fmt) {
/* ... */
typedef time_put<charT, Iter> TimePut;
/* ... */
}
And time_put
's definition is in locale.time.put.virtuals#1:
Effects: Formats the contents of the parameter
t
into characters placed on the output sequences
. Formatting is controlled by the parameters format and modifier, interpreted identically as the format specifiers in the string argument to the standard library functionstrftime()
...