charcoal/OpenGLEngine/Util.cpp

32 lines
639 B
C++
Raw Normal View History

2018-09-05 06:49:02 +00:00
#include "Util.h"
#include <fstream>
#include <string>
2018-09-05 06:49:02 +00:00
#include "Exception.h"
std::string Util::load_file(const std::string& path)
2018-09-05 06:49:02 +00:00
{
std::ifstream input_stream;
try
{
input_stream.open(path);
}
catch (std::ios::failure& e)
2018-09-05 06:49:02 +00:00
{
throw Exception(std::string("Error Opening File: ") + e.what(), "class Util");
}
if (input_stream.is_open())
{
input_stream.seekg(0, std::ios::end);
size_t size = input_stream.tellg();
std::string buffer(size, ' ');
2018-09-05 06:49:02 +00:00
input_stream.seekg(std::ios::beg);
input_stream.read(&buffer[0], size);
return buffer;
}
else
{
throw Exception("Unable to access file: " + path, "class Util");
2018-09-05 06:49:02 +00:00
}
}