Files
stacat/src/utils/readfile.cpp
2025-06-14 00:29:53 +02:00

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;
}
}