I would like to print a chrono time point in the console, and I've found the following stackoverflow question:
How do you print a C++11 time_point?
One of the answers (How do you print a C++11 time_point?) states that in C++20 (which is now out for more than a year) one can just put the time point into an output command. Unfortunately, I can't compile the code on my machine. I have used the following command for the compilation:
g++ -std=c++20 chrono5.cpp -o test
I use this command because I read that C++ 20 is required for the direct output to work.
The file "chrono5.cpp" contains the exact same code as the (edit to the) answer to which the link above points, which was literally written by Howard Hinnant, the creator of the chrono library. What am I doing wrong?
The error message is exceedingly long, whence I probably should not include it in its entirety, but here is its beginning:
chrono5.cpp:7:15: error: no match for ‘operator<<’ (operand types are ‘std::ostream’ {aka ‘std::basic_ostream<char>’} and ‘std::chrono::_V2::system_clock::time_point’ {aka ‘std::chrono::time_point<std::chrono::_V2::system_clock, std::chrono::duration<long int, std::ratio<1, 1000000000> > >’})
7 | std::cout << std::chrono::system_clock::now() << " UTC\n";
| ~~~~~~~~~ ^~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| | |
| | std::chrono::_V2::system_clock::time_point {aka std::chrono::time_point<std::chrono::_V2::system_clock, std::chrono::duration<long int, std::ratio<1, 1000000000> > >}
| std::ostream {aka std::basic_ostream<char>}
Does my compiler have the support for this feature at all? Thank you very much in advance!