Bregma said:
Just a suggestion on tokenizing the string.
#include <iostream> #include <regex> #include <string> #include <vector> using namespace std; /* * This here is the tokenizer. Splits an input string on “I” characters into an arbitrary number * strings appended to the result vector. */ void split_on_sep(string const& src, vector<string>& result) { static const regex marker{"[^|]+"}; auto tokens_begin = sregex_iterator{src.begin(), src.end(), marker}; auto tokens_end = sregex_iterator{}; for (auto t = tokens_begin; t != tokens_end; ++t) result.push_back((*t).str()); } /* * Test it. */ int main() { const string dbstring{"one|two|three"}; vector<string> result; split_on_sep(dbstring, result); for (auto const& s: result) cout << s << "\n"; }
Here's the output.
$ g++ -std=c++14 -o strs strs.cpp && ./strs one two three
All I have to say is, “beautiful ❤️”