From 573bb05f487e490c33c2fa4f201126152d51e4d5 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 23 Jul 2025 13:40:59 +0300 Subject: fix(cli): Simplify implementation of readUserInput --- src/cli.hpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/cli.hpp') diff --git a/src/cli.hpp b/src/cli.hpp index 9a2ca64..6fa9c1b 100644 --- a/src/cli.hpp +++ b/src/cli.hpp @@ -7,18 +7,18 @@ namespace cli { template void readUserInput(T& outValue, const char* enter_message, const char* error_message) { - do { + std::cout << enter_message; + std::cin >> outValue; + + while (std::cin.fail()) { + std::cerr << error_message << std::endl; + + std::cin.clear(); + std::cin.ignore(std::numeric_limits::max(), '\n'); + std::cout << enter_message; std::cin >> outValue; - if (std::cin.fail()) { - std::cerr << error_message << std::endl; - std::cin.clear(); - std::cin.ignore(std::numeric_limits::max(), '\n'); - continue; - } - break; - } while (true); } } -- cgit v1.3.1-26-gb76a