-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsafecin.cpp
69 lines (61 loc) · 1.24 KB
/
safecin.cpp
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
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "safecin.h"
bool safecinbooltrue(void)
{
std::cout << eingabestring;
int a = 0;
std::string x;
bool b;
do{
std::cin >> x;
if(x=="true" || x=="True"|| x=="Ja" || x=="ja" || x=="1" || x=="yes" || x=="Yes")
{
a=1;
b = true;
}
/*False Aussagen */
if(x=="false" || x=="False" || x=="nein" || x=="0" || x=="Nein" || x=="No" || x=="NO")
{
a=1;
b = false;
}
}while(a==0);
return b;
}
int safecinint(void)
{
std::cout << eingabestring;
int b;
std::string::size_type sz;
bool a = false;
do{
std::string x;
std::cin >> x;
try{
b = std::stoi(x, &sz, 10);
return b;
}
catch (std::invalid_argument&)
{
a = false;
}
catch (std::out_of_range&)
{
a = false;
}
}while(a==false);
}
std::string inttostring(int a)
{
try{
std::string str = std::to_string(a);
return str;
}
catch (std::invalid_argument&)
{
a = 0;
}
catch (std::out_of_range&)
{
a = 0;
}
}