Skip to content

Instantly share code, notes, and snippets.

@joelthelion
Created April 27, 2009 09:35
Show Gist options
  • Save joelthelion/102413 to your computer and use it in GitHub Desktop.
Save joelthelion/102413 to your computer and use it in GitHub Desktop.
Parse a string in C++
template<class ElementType>
std::vector<ElementType> parse_string(std::string str,char delim)
{
std::istringstream ss(str);
std::string token;
std::vector<ElementType> result;
while (getline(ss,token,delim))
{
std::istringstream token_parser(token);
ElementType value;
token_parser >> value;
assert(!token_parser.fail());
result.push_back(value);
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment