mirror of
https://gitlab.com/VoidEUW/stacat.git
synced 2025-12-12 15:18:41 +00:00
uploaded current state of stacat
This commit is contained in:
36
src/utils/readfile.cpp
Normal file
36
src/utils/readfile.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include "readfile.h"
|
||||
#include "utils.h"
|
||||
#include "../output.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace debug;
|
||||
using namespace error;
|
||||
|
||||
namespace utils {
|
||||
|
||||
string readfile(const char* filename) {
|
||||
ifstream file(filename);
|
||||
if (!checkfile(file)) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
string data, line;
|
||||
while (getline(file, line)) {
|
||||
data += line;
|
||||
data += '\n';
|
||||
}
|
||||
data.pop_back();
|
||||
file.close();
|
||||
return data;
|
||||
}
|
||||
|
||||
bool checkfile(ifstream& file) {
|
||||
if (!file.is_open()) {
|
||||
throwError(FILE_NOT_FOUND, "File not found", __LINE__, __FILE__);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user