diff options
author | drumsetmonkey <abelleisle@roadrunner.com> | 2016-06-08 08:45:29 -0400 |
---|---|---|
committer | drumsetmonkey <abelleisle@roadrunner.com> | 2016-06-08 08:45:29 -0400 |
commit | a978ddfb98734514874231ed28d0395533afa25d (patch) | |
tree | 0a63a6e9b5c4a74767c054240f5527cc3d3311c8 /src/common.cpp | |
parent | 6f23c384bb07db5e0c4bdaf0a0340d0af47475d8 (diff) | |
parent | 5e4b825513aee44afc1342e5c390e80d3a1fdd15 (diff) |
Lighting!
Diffstat (limited to 'src/common.cpp')
-rw-r--r-- | src/common.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/common.cpp b/src/common.cpp index c643174..bb1ad1e 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -174,6 +174,39 @@ const char *readFile(const char *path) return buf; } +std::string readFile(const std::string& path) +{ + std::ifstream in (path, std::ios::in); + std::string buffer; + + if (!in.is_open()) + UserError("Error reading file " + path); + + in.seekg(0, in.end); + buffer.reserve(in.tellg()); + in.seekg(0, in.beg); + in.read(&buffer[0], buffer.size()); + + in.close(); + return buffer; +} + +std::vector<std::string> readFileA(const std::string& path) +{ + std::ifstream in (path, std::ios::in); + std::vector<std::string> lines; + std::string line; + + if (!in.is_open()) + UserError("Error reading file " + path); + + while(std::getline(in, line)) + lines.push_back(line); + + in.close(); + return lines; +} + void UserError(std::string reason) { std::cout << "User error: " << reason << "!\n"; |