Files
AdventOfCode/2025/Cpp/AdventHelpers/source/InputFileHelper.cpp
2025-12-01 16:29:09 -05:00

43 lines
1003 B
C++

#include "AdventHelpers/InputFileHelper.h"
#include <fstream>
#include <string>
#include <iostream>
namespace AdventHelpers {
// Opens file, reads each line into mLines vector. Returns null on error.
InputFileHelper* InputFileHelper::create(const char* filename) {
InputFileHelper* inputFileHelper = nullptr;
std::ifstream file(filename);
if (file.is_open()) {
inputFileHelper = new InputFileHelper();
std::string line;
while (std::getline(file, line)) {
inputFileHelper->mLines.push_back(line);
}
// Clean up
file.close();
}
else {
std::cerr << "Error: Could not open file " << filename << std::endl;
}
return inputFileHelper;
}
const char* InputFileHelper::getLine() {
return nullptr;
}
void InputFileHelper::destroy(InputFileHelper* inputFileHelper) {
if (inputFileHelper) {
delete inputFileHelper;
} else {
std::cerr << "Warning: Attempted to destroy a null InputFileHelper pointer." << std::endl;
}
}
} // namespace AdventHelper