Is there any Alternate of <dos.h> ?

//to use 'getdate' & 'delay' we include
#include <dos.h>
As we know there is no dos.h header file in UNIX, am working in Xcode
is there any alternate to do this???
I've no idea what getdate does in DOS, but standard C and C++ have plenty of time related functions here.
http://www.cplusplus.com/reference/ctime/

As for a delay, you have choices.
1
2
3
4
5
6
#include <unistd.h>
unsigned int sleep(unsigned int seconds);
int usleep(useconds_t usec);

#include <time.h>
int nanosleep(const struct timespec *req, struct timespec *rem);

Adapting from https://stackoverflow.com/questions/158585/how-do-you-add-a-timed-delay-to-a-c-program:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <chrono>
#include <thread>
#include <iostream>

int main()
{
    using namespace std::this_thread; // sleep_for, sleep_until
    using namespace std::chrono; // nanoseconds, system_clock, seconds

    std::cout << "Start\n";
    sleep_for(nanoseconds(10));
    sleep_until(system_clock::now() + seconds(10));
    std::cout << "End wait\n";
    
}


Start
End wait
Program ended with exit code: 0
unistd ... make it a last resort, its difficult to port off unix systems and is often stuffed into code that can get along without it. Like dos.h and windows.h and so on, it marries your code to an OS and other users have to find a workaround.
Last edited on
uh, you have to include the required headers for stuff. If you want to use usleep(), you need to #include <unistd.h>.

But, as againtry already mentioned, you no longer need to do weirdo stuff like (http://www.cplusplus.com/forum/beginner/139609/#msg738550).
Topic archived. No new replies allowed.