Print service provided by iDogiCat: http://www.idogicat.com/
home logo





Home > IT > Programming > C++ Programming > Frequently Used Linux C++ Code

Frequently Used Linux C++ Code

iDog

sleep

#include 

// Pauses for a specified number of milliseconds
void sleep(int timespan)
{
    clock_t goal = timespan * CLOCKS_PER_SEC / 1000 + clock();
    while(goal > clock())
        ;
}

time

#include 
#include

using namespace std;

int main()
{
    timeval tv;
    gettimeofday(&tv, NULL);

    cout << "seconds: " << tv.tv_sec << endl;
    cout << "Hours: " << tv.tv_sec / 3600 << endl;
    cout << "days: " << tv.tv_sec/3600 / 24 << endl;
    cout << "years: " << tv.tv_sec/3600 / 24 / 365 << endl;
    cout << "usec: " << tv.tv_usec << endl;

    return 0;
}