Created
April 27, 2009 09:35
-
-
Save joelthelion/102413 to your computer and use it in GitHub Desktop.
Parse a string in C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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