Advertisement
Felanpro

Clock (using threads)

Feb 20th, 2019
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include <iostream>
  2. #include <thread>
  3. #include <windows.h>
  4. #include <stdio.h>
  5. #include <conio.h>
  6.  
  7. using namespace std;
  8.  
  9. int counter_variable = 1;
  10.  
  11. void counting_function()
  12. {
  13.     while(1)
  14.     {
  15.         Sleep(1000);
  16.         cout << "\r";
  17.         cout << counter_variable;
  18.         counter_variable++;
  19.     }
  20. }
  21.  
  22. int main()
  23. {
  24.     thread t1(counting_function); //execute thread
  25.  
  26.     int x;
  27.     cin >> x;
  28.  
  29.     t1.join();
  30.  
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement