Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Contrôle du temps avec la bibliothèque chrono c++
- #include <iostream>
- #include <chrono>
- #include <thread>
- #define TEMPO 4
- bool minutor(std::chrono::steady_clock::time_point debut, std::chrono::steady_clock::time_point& fin, std::chrono::seconds tempo) {
- std::chrono::seconds tempsEcoule = std::chrono::duration_cast<std::chrono::seconds>(fin - debut);
- if (tempsEcoule >= tempo) {
- return true;
- } else {
- fin = std::chrono::steady_clock::now();
- }
- return false;
- }
- int main() {
- std::chrono::steady_clock::time_point debut = std::chrono::steady_clock::now(); //debut t
- std::chrono::steady_clock::time_point fin = std::chrono::steady_clock::now();//fin t
- std::chrono::seconds tempo = std::chrono::seconds(TEMPO);//temps à contrôler
- while (true) {
- std::this_thread::sleep_for(std::chrono::milliseconds());//sleep ms Un délai s'ajoute pour compliquer la situation
- if (minutor(debut, fin, tempo)) {
- std::cout << "le temps est écoulé " << std::endl;
- return 0;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement