-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilesOperationFunctions.cpp
More file actions
143 lines (124 loc) · 3.06 KB
/
FilesOperationFunctions.cpp
File metadata and controls
143 lines (124 loc) · 3.06 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include "FilesOperationFunctions.h"
bool FileOperation::ShowFileWithoutWhiteChars_CHAR(string FilePath)
{
ifstream File(FilePath);
char FileChar;
if (File.is_open())
{
while (File.get(FileChar))
{
if (isspace(FileChar)) //sprawdzenie czy spacja
{
continue; //nic nie rób
}
else
cout << FileChar;
}
File.close();
return true;
}
else {
cout << "ERROR IN LOADING FILE" << endl;
return false;
}
}
bool FileOperation::ShowFileWithoutWhiteChars_WCHAR(string FilePath)
{
wifstream File(FilePath);
wchar_t FileChar;
if (File.is_open())
{
while (File.get(FileChar))
{
if (isspace(FileChar)) //sprawdzenie czy spacja
{
continue; //nic nie rób
}
else
wcout << FileChar;
}
File.close();
return true;
}
else {
cout << "ERROR IN LOADING FILE" << endl;
return false;
}
}
int FileOperation::GetMinimumDigitFromFile(string FilePath)
{
ifstream File(FilePath);
vector<int> Numbers;
string CharContainer;
char FileChar;
signed int NumberBuffer;
int MinimalNumber = NULL;
if (File.is_open()) {
while (File.get(FileChar)) // odczyt znaku
{
if (isspace(FileChar)) // jezeli znak jest znakiem bia³ym to:
{
NumberBuffer = atoi(CharContainer.c_str()); //je¿eli po liczbie wystapi znak bia³y to koñczymy wpisywanie cyfry
Numbers.push_back(NumberBuffer); //wpisujemy tê liczbe do wektora przechowuj¹cego zczytane liczby
if (CharContainer.size() > 0)
CharContainer.erase(); //jezeli pojemnik stringa jest pe³ny to go czyœcimy
}
else
CharContainer.push_back(FileChar); //wpisanie do stringa przechowuj¹cego liczbe
}
File.close();
}
else {
cout << "ERROR IN LOADING FILE" << endl;
return NAN;
}
MinimalNumber = *min_element(begin(Numbers), end(Numbers)); //zwrocenie najmniejszej liczby z vectora
return MinimalNumber;
}
bool FileOperation::CopyFile(fstream& FileRead, fstream& FileWrite)
{
string line;
if (FileRead.is_open() && FileWrite.is_open()) {
while (getline(FileRead, line))
FileWrite << line << endl;
return true;
}
else {
cout << "ERROR IN LOADING FILE" << endl;
return false;
}
}
bool FileOperation::CopyArrayToFile(string FilePath, int** Array, int ArraySizeA, int ArraySizeB)
{
fstream File(FilePath, ios::out | ios::binary);
if (File.is_open()) {
for (int i = 0;i < ArraySizeA;i++) {
for (int j = 0;j < ArraySizeB;j++) {
File.write(reinterpret_cast<char*>(&Array[i][j]), sizeof(int));
}
}
File.write(reinterpret_cast<char*>(&ArraySizeA), sizeof(int));
File.write(reinterpret_cast<char*>(&ArraySizeB), sizeof(int));
File.close();
return true;
}
else {
cout << "ERROR IN LOADING FILE" << endl;
return false;
}
}
bool FileOperation::loadArray(string FilePath, int** Array, const int ArraySizeA, const int ArraySizeB)
{
std::ifstream File(FilePath, std::ios::binary | std::ios::in);
if (!File.is_open())
return false;
else {
for (int i = 0;i < ArraySizeA+2;i++) {
for (int j = 0;j < ArraySizeB;j++) {
File.read(reinterpret_cast<char*>(&Array[i][j]), sizeof(int));
}
}
File.close();
}
return true;
}