summaryrefslogtreecommitdiff
path: root/main.cpp
blob: 51262e9c02af59ccdc37d36bcd5294354381415f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <ctime>
#include <sys/time.h>


int main() {
	std::string line;
	while (std::getline(std::cin, line)) {
		struct timeval tv;
		gettimeofday(&tv, nullptr);

		const struct tm *tm = localtime(&tv.tv_sec);

		char buffer[128];
		const ssize_t nw =
			strftime(buffer, sizeof buffer - 7, "%Y-%m-%d %H:%M:%S.", tm);

		int multiplier = 100000;
		for (int i = 0; i < 6; i++) {
			buffer[nw + i] = '0' + tv.tv_usec / multiplier % 10;
			multiplier /= 10;
		}
		buffer[nw + 6] = '\0';

		std::cout << buffer << ' ' << line << std::endl;
	}
}