I am currently working on Advent of Code day 2 and I am trying out some different stuff for the first time. I heard about boost split through a podcast while on the road and immediately wanted to give it a go when I got home.
I have my vector games as the output, the input gameSets, and the delimiter ;.
I was hoping to print each element within games to the console to ensure my elements were correct.
#include <iostream>
#include <fstream>
#include <string>
#include <boost/algorithm/string.hpp>
#include <vector>
vector<std::string> games;
void partOneAnswer() {
// Open File
std::string filePath = "test_values.txt";
std::ifstream stream(filePath);
std::string line;
if (stream.is_open()) {
while (std::getline(stream, line)) {
// printf("%s\n", line.c_str());
std::string delimiter = ":";
std::string gameSets = line.substr(line.find(delimiter) + 2, line.length());
//printf("%s\n", gameSets.c_str());
while (gameSets != "") {
// place each set into a vector, being delimited by ;
boost::split(games, gameSets, ";");
for (int i = 0; i < games.size(); i++) {
std::cout << games[i] + "\n";
}
}
}
}
}
The result was the error.
Any ideas on why?
Error takes me to:
\boost\algorithm\string\detail\finder.hpp 578
Compiling was not an issue until I added boost.
>Solution :
boost::split needs a predicate for its delimiter, you can’t use a string:
boost::split(games, gameSets, boost::is_any_of(";"))