Why does the string returned by ctime()
have a line feed (0x0A
) as its final character? For example, this code:
#include <iostream>
#include <cstdlib>
int main(int argc, char* argv[])
{
time_t now;
time(&now);
char* time_str = ctime(&now);
std::cout << time_str << "why is this on a new line?" << std::endl;
return 0;
}
...produces the following output:
$ ./time.exe
Wed Oct 23 14:52:29 2013
why is this on a new line?
$
It's not a big deal; I can strip the final byte from the string, but why does ctime()
put it there in the first place?