-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiomanager.cpp
executable file
·47 lines (41 loc) · 1.16 KB
/
iomanager.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
#include "iomanager.h"
#include <fstream>
#include <iostream>
std::string IOManager::readTextFile(const std::__cxx11::string& path)
{
std::string out;
std::ifstream file(path);
if (file.fail())
{
std::cout << "IOManager::readTextFile: cannot open " << path
<< std::endl;
throw std::ios_base::failure("Cannot open file.");
}
// Get file size.
file.seekg(0, std::ios::end);
uint fileSize = file.tellg();
file.seekg(0, std::ios::beg);
fileSize -= file.tellg();
out.resize(fileSize);
file.read(&out[0], fileSize);
return out;
}
std::vector<char> IOManager::readBinFile(const std::string& path)
{
std::vector<char> out;
std::ifstream file(path, std::ios_base::binary);
if (file.fail())
{
std::cout << "IOManager::readBinFile: cannot open " << path
<< std::endl;
throw std::ios_base::failure("Cannot open file.");
}
// Get file size.
file.seekg(0, std::ios::end);
uint fileSize = file.tellg();
file.seekg(0, std::ios::beg);
fileSize -= file.tellg();
out.resize(fileSize);
file.read(&out[0], fileSize);
return out;
}