From bf8f3613c439cd4702116177f0c6ea3895f07a23 Mon Sep 17 00:00:00 2001 From: Paul Abib Camano Date: Tue, 1 Mar 2022 02:39:43 +0800 Subject: [PATCH] Added workaround for programs that ask for user input. --- src/_pause.h | 50 +++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/src/_pause.h b/src/_pause.h index 02f9b09..5423459 100644 --- a/src/_pause.h +++ b/src/_pause.h @@ -1,21 +1,29 @@ -/* **************************************************************** - * @author: James Michael Adoremos - * @app name: pause.h - * @app desc: This library shall contain a function that imitates Windows' PAUSE command - * @history: - * - 2018/02/08 - * -- Created _pause() function - * ****************************************************************/ - -#ifndef _PAUSE -#define _PAUSE - -#include - -// A function to imitate Windows' PAUSE command -void _pause() { - std::cout << "Press any key to continue..."; - std::cin.get(); -} - -#endif +/* **************************************************************** + * @author: James Michael Adoremos + * @app name: pause.h + * @app desc: This library shall contain a function that imitates Windows' PAUSE command + * @history: + * - 2018/02/08 + * -- Created _pause() function + * ****************************************************************/ + +#ifndef _PAUSE +#define _PAUSE + +#include + +// A function to imitate Windows' PAUSE command +void _pause() { + std::cout << "Press any key to continue..."; + + /* Clear the input stream if the number of bytes is not 0 + * This is a workaround for programs that ask for user input. + */ + if(sizeof(std::cin) != 0) { + std::cin.ignore(); + } + + std::cin.get(); +} + +#endif