Question Details

No question body available.

Tags

c++ c++-chrono

Answers (3)

May 13, 2026 Score: 5 Rep: 38,508 Quality: Medium Completeness: 70%

The default datatypes used by std::chrono::duration and std::chrono::timepoint are integers (unspecified which one but usually int64t).

Adding std::chrono::duration to std::chrono::systemclock::timepoint will result in a std::chrono::timepoint.

The iostream output operator for systemclock timepoints is explicitly disabled for floating point durations which is why you can't print it.

You can solve both of your problems by ensuring end stays as an integer duration:

std::chrono::system
clock::timepoint end = start + std::chrono::durationcast(timer_duration);
May 13, 2026 Score: 1 Rep: 403 Quality: Low Completeness: 50%

It has been rightly pointed out by Alan Birtles and Comet, the duration value needs to be an integer type to enable straightforward addition of 'start' and 'duration' and subsequent printing. However, I wanted to allow the user to input timer duration as a fraction of a second. So I save the double input into nanoseconds and save that as an integer duration. Changes made:

std::chrono::nanoseconds timerduration((long long)(timer*1000000000));

This allows direct addition and printing as follows:

std::chrono::time
point start, end; //... end = start + timer_duration; std::cout
May 13, 2026 Score: -1 Rep: 1 Quality: Low Completeness: 80%

Question 1 :
You declare start as a std::chrono::timepoint but end is initialised as a addition of start and timerduration which is declared as auto. Auto deduced type with initialization: here start is an int and timeduration a double so the sum is of type double and the auto deduction creates a time point (std::chrono::timepoint) in double. Check (What is the meaning of the auto keyword?) for more explanation.

That's what explains the difference of type between start and end. So, in conclusion, if you want start and end to be of the same type and calculate duration:

std::chrono::timepoint start, end;
std::chrono::duration timerduration(timer); 
start = std::chrono::systemclock::now();
end = start + std::chrono::durationcast(timer_duration);

Question 2 :
Report to question 1, end was a double see more detailed answer of Alan Birtles.