generated from AfonsoCMSousa/CPP-Template
56 lines
1.3 KiB
C++
56 lines
1.3 KiB
C++
/*
|
|
* io.cpp
|
|
*
|
|
* - This file contains basic funcions to read files and parse them
|
|
*
|
|
* - Taken from AfonsoCMSousa (me) advent of code repository:
|
|
* https://github.com/AfonsoCMSousa/AdventOfCode
|
|
*
|
|
* Note: The funtions were changed to better suit the needs of this project, but the original code can be found in the repository above.
|
|
* Created by AfonsoCMSousa on 21/05/2026.
|
|
*/
|
|
|
|
#ifndef FILE_IO_CPP
|
|
#define FILE_IO_CPP
|
|
|
|
#include <cstdint>
|
|
#include <fstream>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
// Reads a file and returns a vector of strings, where each string is a line in the file
|
|
std::vector<std::vector<char>> read_char(const char *filePath)
|
|
{
|
|
std::ifstream file(filePath);
|
|
if (!file.is_open())
|
|
{
|
|
throw std::runtime_error("Could not open file");
|
|
}
|
|
|
|
std::vector<std::vector<char>> lines;
|
|
std::string line;
|
|
|
|
while (std::getline(file, line))
|
|
{
|
|
std::vector<char> charLine(line.begin(), line.end());
|
|
lines.push_back(charLine);
|
|
}
|
|
|
|
file.close();
|
|
return lines;
|
|
}
|
|
|
|
std::vector<uint64_t> get_digits(uint64_t number) {
|
|
std::vector<uint64_t> _return_vec;
|
|
while (number != 0) {
|
|
_return_vec.push_back(number % 10);
|
|
number /= 10;
|
|
}
|
|
std::reverse(_return_vec.begin(), _return_vec.end());
|
|
|
|
return _return_vec;
|
|
}
|
|
|
|
#endif // FILE_IO_CPP
|