-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFileHandler.cpp
62 lines (48 loc) · 1.24 KB
/
FileHandler.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
#include "FileHandler.h"
void OpenFile(std::string fileName, std::wifstream *wifstream)
{
wifstream->open(fileName);
wifstream->imbue(std::locale(std::locale::empty(), new std::codecvt_utf8<wchar_t>));
}
void OpenFile(std::wstring fileName, std::wifstream* wifstream)
{
wifstream->open(fileName);
wifstream->imbue(std::locale(std::locale::empty(), new std::codecvt_utf8<wchar_t>));
}
void OpenFile(std::wstring fileName, std::wofstream* wofstream)
{
wofstream->open(fileName);
wofstream->imbue(std::locale(std::locale::empty(), new std::codecvt_utf8<wchar_t>));
}
int ReadDataFromFile(std::string fileName, std::vector<std::wstring>* dataContainer)
{
std::wstring line;
std::wifstream file;
OpenFile(fileName, &file);
while (!file.fail())
{
std::getline(file, line);
dataContainer->emplace_back(line);
}
dataContainer->pop_back();
file.close();
return 0;
}
bool ReadLineFromFile(std::wifstream* wifstream, std::wstring* input)
{
std::wstring line;
if (wifstream->fail())
{
std::wcout << L"Ïîìèëêà ÷èòàííÿ ôàéëó!\n";
return false;
}
std::getline(*wifstream, line);
(*input) = line;
return true;
}
bool WriteLineToFile(std::wofstream* wofstream, std::wstring output)
{
std::wstring line;
(*wofstream) << output;
return true;
}