#include <iostream>
#include <string>
#include <sstream>
#include <vector>
std::vector<std::string> split(const std::string& input, char delimiter)
{
std::istringstream stream(input);
std::string field;
std::vector<std::string> result;
while (std::getline(stream, field, delimiter)) {
result.push_back(field);
}
if (input.empty() || input.back() == delimiter) {
result.push_back("");
}
return result;
}
void test(const std::string& input)
{
std::cout << "'" << input << "'" << " => [";
for (const std::string& s : split(input, ',')) {
std::cout << "'" << s << "', ";
}
std::cout << "]" << std::endl;
}
int main()
{
test("aaa,bbb,ccc");
test("aaa,bbb,,ccc");
test("aaa,bbb,ccc,");
test("aaa");
test("");
}