vector<string> split(string s, char delimiter){
int n = s.length(), k=0;
vector<string> v;
for(int i=0;i<n;i++){
if(s[i]==delimiter){
string x = s.substr(k,i-k);
k=i+1;
v.push_back(x);
} else if(i==n-1){
string x = s.substr(k,i-k+1);
v.push_back(x);
}
}
return v;
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/5a8125fc-82bd-4247-8da8-3e7b4d62bed7%40isocpp.org.
template< class ForwardIt1, class ForwardIt2, class OutIt >void split( ForwardIt1 first, ForwardIt1 last, ForwardIt2 s_first, ForwardIt2 s_last, OutIt o ) { // 'o' may be anything auto sz = std::distance(s_first, s_last); auto next = first; while ( next != last ) { next = std::search(first, last, s_first, s_last); *o++ = { first, next } ; // <- copy elision guarantee that this is moving ? first = next; std::advance(first, sz); }}