#include <iostream>
#include <thread>
#include <chrono>
#include <ctime>

int main() {
ย ย  int count = 0;
ย ย  auto previous_time = std::chrono::system_clock::now();

ย ย  while (count < 2) {
ย ย ย ย ย ย  auto current_time = std::chrono::system_clock::now();
ย ย ย ย ย ย  if (std::chrono::duration_cast<std::chrono::milliseconds>(current_time - previous_time) >= std::chrono::milliseconds(100)) {
ย ย ย ย ย ย ย ย ย ย  std::cout << "Hello at " << std::ctime(&std::time(nullptr)) << std::endl;
ย ย ย ย ย ย ย ย ย ย  count++;
ย ย ย ย ย ย ย ย ย ย  previous_time = current_time;
ย ย ย ย ย ย  }
ย ย  }

ย ย  std::cout << "Printed 2 'Hello's" << std::endl;

ย ย  return 0;
}


- dc official App