Qbasicnews.com

Full Version: Really nood question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How do I get the time in milliseconds (or something close) in C++. I'm using a time_t data type and setting it to time(NULL). Then when I cout it I typcast it as a double, but it always prints out an integer. Of course I've got the #include <ctime> declaration at the top.

I have to be able to do this without Windows librarys (I'm on OSX) and without intel chipset commands (Its got a Motorola chipset.)
Okaaaay. I guess it wasn't such a noob question. Okay, how do you do it on a PC? XCode has most common C++ PC functions included in libraries.
without windows, dunno, i try not to picture my life without it.

So many games unplayed
So many downloads usable
So many optimizers for morrowind untouchable...

Me: Windows XP Or 2000?
Other Dude: Linux....
me: Get Running.

i know windows does timeGetTime(), maybe #include <ctime> has the answer. I'm gonna have to look into this
Who said anything about Linux? OSX isn't Linux. Looking at my picture and my signature that should be obvious. Secondly, OSX is perfectly happy running Virtual PC and anything you can download and run I can download and run too (except for virii and spyware. :-P)

Anyway it couldn't find timeGetTime(), I assume I need to include something, what header is it?
timeGetTime is declared in mmsystem.h, but afaik that's a windows only thing. I could very possibly be wrong though.

Try GetTimeOfDay from time.h, it returns seconds and milliseconds.

Code:
#include <sys/time.h>

int gettimeofday(struct timeval * tv , struct timezone * tz );

And the timeval struct contains tv_sec and tv_usec, seconds and microseconds. For timezone just pass NULL, it's supposed to return the timezone, but it's obsolete on many systems.
Thanks Zap, worked great.
Quote:Who said anything about Linux? OSX isn't Linux.

I just said Linux because it popped into my head. In all honesty i've never heard of OSX, onlky Windows, Mac and Linux.
OSX is Mac.

<- 1984 Mac commercial

Apple's motto
|
v
What OS you're using should be irrelavent if you're using standardized header files, which are availble through every C++ compiler.
Quote:OSX is Mac.

...0_0 you learn a new, useless fact everyday...

[Image: 20040703.jpg]

ctime sould work fine...and I've heard of clock(), what does that do?