-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConsoleInput.h
executable file
·56 lines (43 loc) · 1.24 KB
/
ConsoleInput.h
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#pragma once
#include <iostream>
#include <string>
#include <sstream>
#include <limits>
using std::string;
using std::stringstream;
using std::getline;
using std::cin;
using std::cout;
using std::endl;
class ConsoleInput {
public:
static ConsoleInput* getInstance();
void flushStandardInput();
void getUserInput();
string getLineCin();
void clearConsoleScreen();
int getIntCin(const char* message, const char* errorMessage, int min = 0, int size = std::numeric_limits<int>::max());
template<typename NumberType>
NumberType getNumberCin(const char* message, const char* errorMessage, NumberType min = 0, NumberType size = std::numeric_limits<NumberType>::max()) {
NumberType number;
do {
cout << message << std::flush;
string numberStr = getLineCin();
stringstream strstream(numberStr);
if (strstream >> number) {
if (number >= min && number < size)
break;
else
cout << errorMessage << endl;
} else {
cout << errorMessage << endl;
}
} while (true);
return number;
}
bool getYesNoCin(const char* message, const char* errorMessage = " -> Incorrect answer! Insert Y or N!\n");
private:
ConsoleInput() {}
virtual ~ConsoleInput() {}
static ConsoleInput* instance;
};