-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathErrorCatcher.cpp
More file actions
57 lines (49 loc) · 1.42 KB
/
Copy pathErrorCatcher.cpp
File metadata and controls
57 lines (49 loc) · 1.42 KB
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
#include "Header.h"
#include <iostream>
#include <fstream>
#include <stdexcept>
// Для ifstream (чтения)
void Fail_To_Close_File(std::ifstream& fs) {
fs.close();
if (fs.is_open()) {
std::cout << "Error! File is still open" << std::endl;
}
}
void Fail_To_Open_File(std::ifstream& fs) {
if (!fs.is_open()) {
std::cout << "Error: failed to open load file!\n";
throw std::runtime_error("Failed to open file");
}
}
// Для ofstream (записи)
void Fail_To_Close_File(std::ofstream& fs) {
fs.close();
if (fs.is_open()) {
std::cout << "Error! File is still open" << std::endl;
}
}
void Fail_To_Open_File(std::ofstream& fs) {
if (!fs.is_open()) {
std::cout << "Error: failed to open load file!\n";
throw std::runtime_error("Failed to open file");
}
}
void File_Is_Empty(std::ofstream& fs) {
if (fs.is_open()) {
std::streampos currentPos = fs.tellp();
fs.seekp(0, std::ios::end);
if (fs.tellp() == 0) {
std::cout << "Error: File is empty!" << std::endl;
}
fs.seekp(currentPos);
}
}
std::string Check_Save_Status(std::ofstream& fs, std::string path) {
fs.close();
if (fs.is_open()) {
std::cout << "Error! File is still open" << std::endl;
return "error";
}
std::cout << "\nGame saved successfully to '" << path << "'!\n";
return "success";
}