Summary Files Commits Branches @commit @diff @stats
path: root / src / cli.hpp
blob: 6fa9c1b3ada44b58467e5e079371b79c206fdf26 (plain) (blame)
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
#ifndef GS_CLI
#define GS_CLI

#include <iostream>
#include <limits>

namespace cli {
	template <typename T>
	void readUserInput(T& outValue, const char* enter_message, const char* error_message) {
		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<std::streamsize>::max(), '\n');

			std::cout << enter_message;
			std::cin >> outValue;

	}
}

#endif /* GS_CLI */