Skip to content

Instantly share code, notes, and snippets.

@recuraki
Last active June 22, 2021 04:46
Show Gist options
  • Select an option

  • Save recuraki/96a575f93723734cef6db982de3c2481 to your computer and use it in GitHub Desktop.

Select an option

Save recuraki/96a575f93723734cef6db982de3c2481 to your computer and use it in GitHub Desktop.
boostでのsplit
#include <iostream>
#include <string>
#include <vector>
#include <boost/algorithm/string/classification.hpp> // is_any_of
#include <boost/algorithm/string/split.hpp>
#include <boost/range/algorithm/for_each.hpp>
using namespace std;
void test(string s){
vector<std::string> result;
cout << "Parse STR: \"" << s << "\"\n";
boost::algorithm::split(result, s, boost::is_any_of(","));
cout << " result array size: " << result.size() << "\n";
for(int i=0; i < (int)result.size(); i++){
cout << " array[i=" << i << "] size: " << result[i].size() << "\n";
}
}
int main()
{
test("1,2,3");
test("1");
test(",");
test("");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment