Created
May 1, 2020 14:57
-
-
Save ArunTS96/e7c0d188954bfeb4bec89d13f3b6d3dc to your computer and use it in GitHub Desktop.
Split std::basic_string to std::vector for any character as delimeter
This file contains hidden or 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 Char, typename Out> | |
void Split(const std::basic_string<Char>& s, Char delim, Out result) { | |
std::basic_istringstream<Char, std::char_traits<Char>, std::allocator<Char>> iss(s); | |
std::basic_string<Char> item; | |
while (std::getline(iss, item, delim)) { | |
*result++ = item; | |
} | |
} | |
template <class Char> | |
std::vector<std::basic_string<Char>> Split(const std::basic_string<Char>& s, Char delim) | |
{ | |
std::vector<std::basic_string<Char>> elems; | |
Split<Char>(s, delim, std::back_inserter(elems)); | |
return elems; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment