mirror of
https://gitlab.com/VoidEUW/stacat.git
synced 2025-12-12 07:08:40 +00:00
37 lines
756 B
C++
37 lines
756 B
C++
#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;
|
|
}
|
|
}
|