CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <chrono>
#include <thread>
#include <iomanip>
#include <atomic>
using namespace std;
// Atomic flag to safely communicate between threads
atomic<bool> stopTimer(false);
// Timer function runs in a separate thread
void timer() {
int y = 0; // Seconds
int z = 0; // Minutes
while (!stopTimer) {
cout << setfill('0') << setw(2) << z << ":"
<< setfill('0') << setw(2) << y << endl;
this_thread::sleep_for(chrono::seconds(1));
y++;
if (y > 59) {
y = 0;
z++;
}
}
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run