C++ gurus - I need a bit of help!

KarsinTheHutt

Golden Member
Jun 28, 2000
1,687
0
0
How do I retrieve the time from the computer's clock? What header file do I need?

my compiler says that std::time() takes in a double to a pointer - so this clearly not what i want
 

KarsinTheHutt

Golden Member
Jun 28, 2000
1,687
0
0
sh!t

:D

My program's srand() can't seed very randomly unless i can retrieve the time and use that as a seed.
 

gittyup

Diamond Member
Nov 7, 2000
5,036
0
0
This is what I use on a unix based system...

#include <time.h>

time_t myTime;
myTime = time(NULL);
cout << ctime(&amp;myTime) << endl;
 

satori

Senior member
Nov 2, 1999
471
0
0
Have you tried this:

srand( (unsigned) time(NULL) );

Even though the time() function doesn't return a value that's type &quot;unsigned&quot;, the return's still the current time in a weird form (for VC++, it's stored in an &quot;long&quot;), so you can still seed the random number generator with it.

Hope that helps.

Sat

btw, this is from the .H files in VC++, so YMMV. :)
 

Blayze

Diamond Member
Feb 22, 2000
6,152
0
0
sorry I dont have an answer just started working with C++ so I don't know much :(