为什么ctime()
返回的字符串的最后一个字符是换行符(0x0A
)?例如,此代码:
#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;
}
.生成以下输出:
$ ./time.exe
Wed Oct 23 14:52:29 2013
why is this on a new line?
$
这没什么大不了的;我可以从字符串中go 掉最后一个字节,但是为什么ctime()
会把它放在第一位呢?