-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.hpp
51 lines (43 loc) · 1.08 KB
/
utils.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#pragma once
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
using namespace std;
namespace aoc_utils
{
string readFile(string fn)
{
ifstream file;
file.open(filesystem::canonical(fn));
stringstream outstring;
string line;
while (getline(file, line))
{
outstring << line << '\n';
}
file.close();
return outstring.str();
}
vector<string> split_string(string &to_split, string delim)
{
string throwaway = to_split;
vector<string> out;
size_t pos = 0;
string token;
while ((pos = throwaway.find(delim)) != string::npos) {
token = throwaway.substr(0, pos);
out.push_back(token);
throwaway.erase(0, pos + delim.length());
}
// last item is out of the loop and becomes throwaway (aka to_split)
if (!throwaway.empty())
out.push_back(throwaway);
return out;
}
int char_to_int(char& val)
{
return val - '0';
}
}