• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

Time ... reading the system clock in c++

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

Robbiem01

Member
Joined
Feb 9, 2002
say for some reason I wanted a program to read from the clock before it started a task then when it was done read from the system clock again and see how long it took. How do I read from a clock in C++? Is it in #include<time.h>? If it is a function included in some standard library can someone please modify my following example code so it outputs the time it took to run through a simple for loop.

//Here it reads from clock and stores time in a varible

for (int i = 0; i < 100; i++) {
cout << i << endl;
}

//And now it reads from the clock again and finds the difference from current time and first recorded time and outputs it to tell the user.


Please fill in the comments with real code if you know how to retrieve time from the computer in C/++ or if you know of a website that has this kind of information a link is worth 1,000 posted replys.
 

XWRed1

Senior Member
Joined
Oct 31, 2001
Uh... shouldn't this be in the programming forum? What you are asking seems pretty os-agnostic.