Skip to content

Instantly share code, notes, and snippets.

@jiemojiemo
Created June 25, 2018 07:16
Show Gist options
  • Save jiemojiemo/f5dad264eda499b7723ebb28e881a4ce to your computer and use it in GitHub Desktop.
Save jiemojiemo/f5dad264eda499b7723ebb28e881a4ce to your computer and use it in GitHub Desktop.
Cpp-split a string
void SplitString(const std::string& s, std::vector<std::string>& v, const std::string& c)
{
std::string::size_type pos1, pos2;
pos2 = s.find(c);
pos1 = 0;
while(std::string::npos != pos2)
{
v.push_back(s.substr(pos1, pos2-pos1));
pos1 = pos2 + c.size();
pos2 = s.find(c, pos1);
}
if(pos1 != s.length())
v.push_back(s.substr(pos1));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment