Split 2025 into lang
This commit is contained in:
42
2025/Cpp/AdventHelpers/source/InputFileHelper.cpp
Normal file
42
2025/Cpp/AdventHelpers/source/InputFileHelper.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#include "AdventHelpers/InputFileHelper.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
namespace AdventHelper {
|
||||
// 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
|
||||
Reference in New Issue
Block a user