Skip to content

Instantly share code, notes, and snippets.

@denkiwakame
Created January 5, 2015 13:22
Show Gist options
  • Save denkiwakame/c665e50c85eb4edbd055 to your computer and use it in GitHub Desktop.
Save denkiwakame/c665e50c85eb4edbd055 to your computer and use it in GitHub Desktop.
getline for split
#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);
}
return result;
}
int main()
{
const std::string input = "aaa,bbb,ccc";
for (const std::string& s : split(input, ',')) {
std::cout << s << std::endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment