-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlatin.cpp
65 lines (59 loc) · 1.72 KB
/
latin.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
//-----------------------------------------------------------------------
// Source : latin.cpp
// Last modified : 31.03.2023
// Version : 10
// Description : Contains functions from "libs/latin.h"
//-----------------------------------------------------------------------
#include "latin.h"
using namespace std;
// Ensures safe opening of the file
void openFile(fstream& file, string path, ios::openmode mode, bool isLogNote) {
file.open(path, mode);
if (!file.is_open()) {
string output = "Íå óäàëîñü îòêðûòü ôàéë ";
output += path;
cout << output;
_getch();
mainLog.print({ "=F= !!! Unable to open ", path });
mainLog.noteExit(9909);
}
else if (isLogNote == true) {
mainLog.print({ "=F= File ", path, " opened successfully" });
}
}
// Converts char to int
int charToInt(char c) {
return (int)(c - 48);
}
// Converts int to string
// minLength - minimum length of string convertation
// # intToStr(43, 4) = "0043"
// When you don't need a specific length recommended to minLength = 0
string intToStr(int num, int minLength) {
string result;
bool isNegative = false;
if (num == 0)
return "0";
if (num < 0) {
isNegative = true;
num = -num;
}
while (num > 0) {
result += (char)(num % 10 + 48);
num /= 10;
}
while (result.size() < minLength) {
result += '0';
}
if (isNegative == true) {
result += '-';
}
reverse(result.begin(), result.end());
return result;
}
// Returns integer entered by the user
int inputInt() {
int tempInt;
cin >> tempInt;
return tempInt;
}