able to read the input and split input into two strings

This commit is contained in:
Stedd 2024-12-01 13:19:04 +01:00
parent acaa1d78be
commit da436272dc
3 changed files with 49 additions and 2 deletions

View File

@ -4,8 +4,12 @@
#include "day01.h"
#include <fstream>
#include <iostream>
#include <list>
#include <ostream>
#include <bits/fs_fwd.h>
#include <bits/fs_path.h>
/*
--- Day 1: Historian Hysteria ---
@ -71,5 +75,28 @@ Your actual left and right lists contain many location IDs. What is the total di
void day01::Run()
{
std::cout << "Day 01" << std::endl;
std::list<int> col1;
std::list<int> col2;
// std::ifstream input("input/day01.txt");
std::ifstream input("input/day01short.txt");
if (!input)
{
std::cerr << "Failed to open input file." << std::endl;
std::cout << "Current path is " << std::filesystem::current_path() << '\n';
return;
}
std::string delimiter = " ";
auto delimiterLength = delimiter.length();
std::string line;
while (std::getline(input, line))
{
auto delimiterPos = line.find(delimiter);
std::string firstNumber = line.substr(0, delimiterPos);
std::string secondNumber = line.substr(delimiterPos + delimiterLength, line.length());
}
}

View File

@ -997,4 +997,4 @@
30895 46438
69966 25582
31783 85509
97288 51968
97288 51968

20
input/day01short.txt Normal file
View File

@ -0,0 +1,20 @@
66845 37619
94793 99076
76946 36179
27374 48777
47847 92154
83270 97857
19354 94331
69716 58559
16902 36957
51817 88003
40758 64262
39074 90635
34632 79874
64980 96787
96137 94559
55489 98589
95130 76776
50275 50416
46438 49722
34182 49722