I was just wondering about the header file "time.h" i havent used it really and what information can you get from it and how (date, hour, year, etc.)
Thanks in Advance!
I was just wondering about the header file "time.h" i havent used it really and what information can you get from it and how (date, hour, year, etc.)
Thanks in Advance!
You can use it to get the current time
and you can use it to generate a random numberCode:#include <iostream> #include <ctime> using namespace std; int main() { time_t TheTime; time(&TheTime); cout <<ctime(&TheTime)<<endl; cin.get(); }
and im sure there are plenty of other uses for itCode:#include <iostream> #include <ctime> using namespace std; int main() { srand ((unsigned)time(0)); int a_random_number = rand()%10; // generates a random number between 1-10 cout <<"The number is "<<a_random_number<<endl; cin.get(); }
>what information can you get from it
References are good.
There's a good introduction to <ctime> / <time.h> in the Programming FAQ. (The examples in the FAQ use the "old" dot-h headers.)
Note that <ctime> uses pointers and structures. So, if you don't know about these yet, you won't fully understand <ctime>.
cgod,
Your second example requires <cstdlib> for the srand/rand functions (granted, it may compile without it because the header may happen to be included elsewhere, or automatically by the compiler, it is still a good idea to have the #include there for portability and predictability).
Cheers
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.