Fireworks Engine  v2.0
Lightweight Sandbox Game Engine using OpenGL for additional Customisation and Quick Prototyping
fileutils.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <iostream>
5 
6 namespace fireworks { namespace utils {
7 
9  class FileUtils
10  {
11  public:
15  static std::string read_file(const char* filepath)
16  {
17  FILE* file = fopen(filepath, "r");
18  if (file == NULL)
19  {
20  // Log this!
21  std::cerr << "ERROR::FILE::Cannot read the file - Please check the file path or permissions " << '\n';
22  return 0;
23  }
24  fseek(file, 0, SEEK_END);
25  unsigned long length = ftell(file);
26  char* data = new char[length + 1];
27  memset(data, 0, length + 1);
28  fseek(file, 0, SEEK_SET);
29  fread(data, 1, length, file);
30  fclose(file);
31 
32  std::string result(data);
33  delete[] data;
34  return result;
35  }
36  };
37 } }
Definition: audioclip.cpp:3
static std::string read_file(const char *filepath)
Reads the contents of the file and converts into stream of bytes.
Definition: fileutils.h:15
A utility class to load various types of files.
Definition: fileutils.h:9