ctime.cpp 765 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * cxxomfort example: chinese_zodiac
  3. *
  4. * See https://rosettacode.org/wiki/Chinese_zodiac
  5. *
  6. */
  7. #include <cxxomfort/base.hpp>
  8. #include <cxxomfort/string_view.hpp>
  9. #include <cxxomfort/ctime.hpp>
  10. #include <cxxomfort/array.hpp>
  11. #include <string>
  12. #include <iostream>
  13. void mysleep (unsigned);
  14. int main () {
  15. using namespace std;
  16. std::timespec ts;
  17. for (unsigned i=0; i < 10; ++i) {
  18. timespec_get(&ts, TIME_UTC);
  19. printf("%lu , %lu\n", ts.tv_sec, ts.tv_nsec);
  20. fflush(stdout);
  21. mysleep(500);
  22. }
  23. }
  24. #if defined(_POSIX_VERSION)
  25. #include <time.h>
  26. void mysleep (unsigned u) {
  27. usleep(u*1000);
  28. }
  29. #elif defined(_WIN32)
  30. // #include <windef.h>
  31. // #include <winbase.h>
  32. // #include <winsock2.h>
  33. #include <windows.h>
  34. void mysleep (unsigned u) {
  35. Sleep(u);
  36. }
  37. #endif