-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.h
42 lines (29 loc) · 866 Bytes
/
helpers.h
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
#ifndef HELPERS_H
#define HELPERS_H
#include <string>
#include <iostream>
#include <string>
#include <fstream>
#define LOGERR(msg) std::cerr << msg << '\n';
inline char* readFile(const std::string& filename, int* outLength) {
std::ifstream file(filename, std::ifstream::binary);
file.seekg (0, file.end);
int length = static_cast<int>(file.tellg());
file.seekg (0, file.beg);
// std::cerr << "File length: " << length << '\n';
char* buffer = new char [length];
file.read(buffer, length);
//buffer[length] = 0;
if (file) {
// std::cerr << "all characters read successfully.\n";
}
else {
std::cerr << "error: only " << file.gcount() << " could be read\n";
delete[] buffer;
buffer = nullptr;
}
file.close();
*outLength = length;
return buffer;
}
#endif // HELPERS_H