hi,

i am having a project where i must implement a method that takes measurements(random numbers) on specific time intervals.This means that i should read (for example) a number every 5minites...I ve been told for a sleep function but i can't find any info about it....Any thoughts on how i should implement this method?:confused:

also is there any way to read the system time through c++?{to know what time appears in the system clock}

thanks in advance for your help....:)
Nicolas

Recommended Answers

All 5 Replies

I ve been told for a sleep function but i can't find any info about it....Any thoughts on how i should implement this method?

If you are using Linux, then this for sleep and if you are using windows then this.

also is there any way to read the system time through c++?{to know what time appears in the system clock}

Yes there is, use the header file #include <ctime> if using C++ or #include <time.h> if using C. For the header reference see here and here.

thanks in advance for your help....Nicolas

Glad we could help.

so i shoud implement that function as thread?{In order to call the sleep function on that thread....}

No need to complicate matters, here is a simple way of using the function..

#include <iostream>
#include <windows.h>
using namespace std;
 
int main(int argc, char** argv)
{
    cout << "Hello" << endl ;
    cout << "Wait for 3 seconds..." << endl ;
    Sleep(5000) ; // takes the time in milliseconds ( 1 second = 1000 milliseconds)
    cout << "World" ;
    getchar( ) ;
    return 0 ;
}

thanks alot!

Thanks I just found this through google great help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.