-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileManager.cpp
More file actions
73 lines (54 loc) · 1.62 KB
/
fileManager.cpp
File metadata and controls
73 lines (54 loc) · 1.62 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
#include "fileManager.h"
std::string readKey(std::string fileName)
{
std::ifstream tempFile(fileName);
std::string tempString = "";
if (tempFile.is_open())
{
std::string subString = "";
while (getline(tempFile, subString))
{
tempString += subString;
}
tempFile.close();
}
return tempString;
}
std::vector<char>* fileToVector(std::string fileName)
{
printf("\nLoading file please wait...\n\n");
std::ifstream myFile(fileName, std::ios_base::binary | std::ios_base::in);
std::vector<char>* newVector = new std::vector<char>();
if (myFile.is_open())
{
std::vector<char> buffer((std::istreambuf_iterator<char>(myFile)),
(std::istreambuf_iterator<char>()));
myFile.close();
for (int x = 0; x < buffer.size(); x++)
{
newVector->push_back(buffer[x]);
}
printf("Done loading\n");
return newVector;
}
printf("\nfailed to open exsisting file\n");
return newVector;
}
bool vectorToFile(std::string fileName, std::vector<char> *buffer)
{
printf("\nSaving file please wait...");
std::ofstream yourFile(fileName, std::ios_base::binary | std::ios_base::out);
if (yourFile.is_open())
{
std::vector<char> tempVector;
for (int x = 0; x < buffer->size(); x++)
{
tempVector.push_back((*buffer)[x]);
}
yourFile.write(reinterpret_cast<char*>(&tempVector[0]), tempVector.size());
yourFile.close();
return true;
}
printf("\nfailed to open new file\n");
return false;
}